home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / etc / faxaddmodem.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1994-08-01  |  81KB  |  2,559 lines

  1. #! /bin/sh
  2. #    $Header: /usr/people/sam/fax/etc/RCS/faxaddmodem.sh,v 1.104 1994/04/25 17:05:34 sam Rel $
  3. #
  4. # FlexFAX Facsimile Software
  5. #
  6. # Copyright (c) 1990, 1991, 1992, 1993, 1994 Sam Leffler
  7. # Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
  8. # Permission to use, copy, modify, distribute, and sell this software and 
  9. # its documentation for any purpose is hereby granted without fee, provided
  10. # that (i) the above copyright notices and this permission notice appear in
  11. # all copies of the software and related documentation, and (ii) the names of
  12. # Sam Leffler and Silicon Graphics may not be used in any advertising or
  13. # publicity relating to the software without the specific, prior written
  14. # permission of Sam Leffler and Silicon Graphics.
  15. # THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  16. # EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  17. # WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  18. # IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19. # ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20. # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. # WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  22. # LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  23. # OF THIS SOFTWARE.
  24. #
  25.  
  26. #
  27. # faxaddmodem [tty]
  28. #
  29. # This script interactively configures a FlexFAX server
  30. # from keyboard input on a standard terminal.  There may
  31. # be some system dependencies in here; hard to say with
  32. # this mountain of shell code!
  33. #
  34. PATH=/bin:/usr/bin:/etc
  35. test -d /usr/ucb  && PATH=$PATH:/usr/ucb        # Sun and others
  36. test -d /usr/bsd  && PATH=$PATH:/usr/bsd        # Silicon Graphics
  37. test -d /usr/5bin && PATH=/usr/5bin:$PATH:/usr/etc    # Sun and others
  38. test -d /usr/sbin && PATH=/usr/sbin:$PATH        # 4.4BSD-derived
  39.  
  40. OS=`uname -s 2>/dev/null || echo unknown`        # system identification
  41. case "$OS" in
  42. # believable values...
  43. IRIX|*BSD*|*bsd*|SunOS|Linux|ULTRIX|HP-UX) ;;
  44. *)  if [ -d /etc/saf ]; then
  45.     # uname -s is unreliable on svr4 as it can return the nodename
  46.     OS=svr4
  47.     fi
  48.     ;;
  49. esac
  50. SPEEDS="76800 57600 38400 19200 9600 4800 2400 1200"    # set of speeds to try
  51. SPEED=
  52.  
  53. while [ x"$1" != x"" ] ; do
  54.     case $1 in
  55.     -os)    OS=$2; shift;;
  56.     -s)        SPEED=$2; shift;;
  57.     -*)        echo "Usage: $0 [-os OS] [-s SPEED] [ttyname]"; exit 1;;
  58.     *)        TTY=$1;;
  59.     esac
  60.     shift
  61. done
  62.  
  63. #
  64. # Deduce the effective user id:
  65. #   1. POSIX-style, the id program
  66. #   2. the old whoami program
  67. #   3. last gasp, check if we have write permission on /dev
  68. #
  69. euid=`id|sed -e 's/.*uid=[0-9]*(\([^)]*\)).*/\1/'`
  70. test -z "$euid" && euid=`whoami 2>/dev/null`
  71. test -z "$euid" -a -w /dev && euid=root
  72. if [ "$euid" != "root" ]; then
  73.     echo "Sorry, but you must run this script as the super-user!"
  74.     exit 1
  75. fi
  76.  
  77. SPOOL=/usr/spool/fax        # top of fax spooling tree
  78. CPATH=$SPOOL/etc/config        # prefix of configuration file
  79. LOCKDIR=/usr/spool/locks    # UUCP locking directory
  80. OUT=/tmp/addmodem$$        # temp file in which modem output is recorded
  81. SVR4UULCKN=$SPOOL/bin/lockname    # SVR4 UUCP lock name construction program
  82. ONDELAY=$SPOOL/bin/ondelay    # prgm to open devices blocking on carrier
  83. CAT="cat -u"            # something to do unbuffered reads and writes
  84. FAX=fax                # identity of the fax user
  85. SERVICES=/etc/services        # location of services database
  86. INETDCONF=/usr/etc/inetd.conf    # default location of inetd configuration file
  87. ALIASES=/usr/lib/aliases    # default location of mail aliases database file
  88. SGIPASSWD=/etc/passwd.sgi    # for hiding fax user from pandor on SGI's
  89. PASSWD=/etc/passwd        # where to go for password entries
  90. PROTOUID=uucp            # user who's uid we use for FAX user
  91. defPROTOUID=3            # use this uid if PROTOUID doesn't exist
  92. GROUP=/etc/group        # where to go for group entries
  93. PROTOGID=nuucp            # group who's gid we use for FAX user
  94. defPROTOGID=10            # use this gid if PROTOGID doesn't exist
  95. SERVERDIR=/usr/etc        # directory where servers are located
  96. QUIT=/usr/local/bin/faxquit    # cmd to terminate server
  97. MODEMCONFIG=$SPOOL/etc        # location of prototype modem config files
  98.  
  99. #
  100. # Deal with known alternate locations for system files.
  101. #
  102. PickFile()
  103. {
  104.     for i do
  105.     test -f $i && { echo $i; return; }
  106.     done
  107.     echo $1
  108. }
  109. INETDCONF=`PickFile    $INETDCONF /etc/inetd.conf /etc/inet/inetd.conf`
  110. ALIASES=`PickFile    $ALIASES   /etc/aliases`
  111. SERVICES=`PickFile    $SERVICES  /etc/inet/services`
  112. test -f /etc/master.passwd            && PASSWD=/etc/master.passwd
  113.  
  114. #
  115. # Setup the password file manipulation functions according
  116. # to whether we have System-V style support through the
  117. # passmgmt program, or BSD style support through the chpass
  118. # program.  If neither are found, we setup functions that
  119. # will cause us to abort if we need to munge the password file.
  120. #
  121. if [ -f /bin/passmgmt -o -f /usr/sbin/passmgmt ]; then
  122.     addPasswd()
  123.     {
  124.     passmgmt -o -a -c 'Facsimile Agent' -h $4 -u $2 -g $3 $1
  125.     }
  126.     deletePasswd()
  127.     {
  128.     passmgmt -d $1
  129.     }
  130.     modifyPasswd()
  131.     {
  132.     passmgmt -m -h $4 -u $2 -o -g $3 $1
  133.     }
  134.     lockPasswd()
  135.     {
  136.     passwd -l $1
  137.     }
  138. elif [ -f /usr/bin/chpass ]; then
  139.     addPasswd()
  140.     {
  141.     chpass -a "$1:*:$2:$3::0:0:Facsimile Agent:$4:"
  142.     }
  143.     modifyPasswd()
  144.     {
  145.     chpass -a "$1:*:$2:$3::0:0:Facsimile Agent:$4:"
  146.     }
  147.     lockPasswd()
  148.     {
  149.     return 0                # entries are always locked
  150.     }
  151. elif [ -f /etc/useradd -o -f /usr/sbin/useradd ]; then
  152.     addPasswd()
  153.     {
  154.     useradd -c 'Facsimile Agent' -d $4 -u $2 -o -g $3 $1
  155.     }
  156.     deletePasswd()
  157.     {
  158.     userdel $1
  159.     }
  160.     modifyPasswd()
  161.     {
  162.     usermod -m -d $4 -u $2 -o -g $3 $1
  163.     }
  164.     lockPasswd()
  165.     {
  166.     passwd -l $1
  167.     }
  168. else
  169.     addPasswd()
  170.     {
  171.     echo "Help, I don't know how to add a passwd entry!"; exit 1
  172.     }
  173.     modifyPasswd()
  174.     {
  175.     echo "Help, I don't know how to modify a passwd entry!"; exit 1
  176.     }
  177. fi
  178.  
  179. #
  180. # Figure out which brand of echo we have and define
  181. # prompt and printf shell functions accordingly.
  182. # Note that we assume that if the System V-style
  183. # echo is not present, then the BSD printf program
  184. # is available.
  185. #
  186. if [ `echo foo\\\c`@ = "foo@" ]; then
  187.     # System V-style echo supports \r
  188.     # and \c which is all that we need
  189.     prompt()
  190.     {
  191.        echo "$* \\c"
  192.     }
  193.     printf()
  194.     {
  195.        echo "$*\\c"
  196.     }
  197. elif [ "`echo -n foo`@" = "foo@" ]; then
  198.     # BSD-style echo; use echo -n to get
  199.     # a line without the trailing newline
  200.     prompt()
  201.     {
  202.        echo -n "$* "
  203.     }
  204. else
  205.     # something else; do without
  206.     prompt()
  207.     {
  208.     echo "$*"
  209.     }
  210. fi
  211. t=`printf hello` 2>/dev/null
  212. if [ "$t" != "hello" ]; then
  213.     echo "You don't seem to have a System V-style echo command"
  214.     echo "or a BSD-style printf command.  I'm bailing out..."
  215.     exit 1
  216. fi
  217.  
  218. #
  219. # If the killall program is not present on the system
  220. # cobble together a shell function to emulate the
  221. # functionality that we need.
  222. #
  223. (killall -l >/dev/null) 2>/dev/null || {
  224.     killall()
  225.     {
  226.     # NB: ps ax should give an error on System V, so we try it first!
  227.     pid="`ps ax 2>/dev/null | grep $2 | grep -v grep | awk '{print $1;}'`"
  228.     test "$pid" ||
  229.         pid="`ps -e | grep $2 | grep -v grep | awk '{print $2;}'`"
  230.     test "$pid" && kill $1 $pid; return
  231.     }
  232. }
  233.  
  234. #
  235. # Prompt the user for a string that can not be null.
  236. #
  237. promptForNonNullStringParameter()
  238. {
  239.     x=""
  240.     while [ -z "$x" ]; do
  241.     prompt "$2 [$1]?"; read x
  242.     if [ "$x" ]; then
  243.         # strip leading and trailing white space
  244.         x=`echo "$x" | sed -e 's/^[     ]*//' -e 's/[     ]*$//'`
  245.     else
  246.         x="$1"
  247.     fi
  248.     done
  249.     param="$x"
  250. }
  251.  
  252. #
  253. # Prompt the user for a numeric value.
  254. #
  255. promptForNumericParameter()
  256. {
  257.     x=""
  258.     while [ -z "$x" ]; do
  259.     prompt "$2 [$1]?"; read x
  260.     if [ "$x" ]; then
  261.         # strip leading and trailing white space
  262.         x=`echo "$x" | sed -e 's/^[     ]*//' -e 's/[     ]*$//'`
  263.         match=`expr "$x" : "\([0-9]*\)"`
  264.         if [ "$match" != "$x" ]; then
  265.         echo ""
  266.         echo "This must be entirely numeric; please correct it."
  267.         echo ""
  268.         x="";
  269.         fi
  270.     else
  271.         x="$1"
  272.     fi
  273.     done
  274.     param="$x"
  275. }
  276.  
  277. #
  278. # Prompt the user for a C-style numeric value.
  279. #
  280. promptForCStyleNumericParameter()
  281. {
  282.     x=""
  283.     while [ -z "$x" ]; do
  284.     prompt "$2 [$1]?"; read x
  285.     if [ "$x" ]; then
  286.         # strip leading and trailing white space and C-style 0x prefix
  287.         x=`echo "$x" | sed -e 's/^[     ]*//' -e 's/[     ]*$//'`
  288.         match=`expr "$x" : "\([0-9]*\)" \| "$x" : "\(0x[0-9a-fA-F]*\)"`
  289.         if [ "$match" != "$x" ]; then
  290.         echo ""
  291.         echo "This must be entirely numeric; please correct it."
  292.         echo ""
  293.         x="";
  294.         fi
  295.     else
  296.         x="$1"
  297.     fi
  298.     done
  299.     param="$x"
  300. }
  301.  
  302. #
  303. # Start of system-related setup checking.  All this stuff
  304. # should be done outside this script, but we check here
  305. # so that it's sure to be done before starting up a fax
  306. # server process.
  307. echo "Verifying that your system is setup properly for fax service..."
  308.  
  309. faxUID=`grep "^$PROTOUID:" $PASSWD | cut -d: -f3`
  310. if [ -z "$faxUID" ]; then faxUID=$defPROTOUID; fi
  311. faxGID=`grep "^$PROTOGID:" $GROUP | cut -d: -f3`
  312. if [ -z "$faxGID" ]; then faxGID=$defPROTOGID; fi
  313.  
  314. #
  315. # Change the password file entry for the fax user.
  316. #
  317. fixupFaxUser()
  318. {
  319.     emsg1=`modifyPasswd $FAX $faxUID $faxGID $SPOOL 2>&1`
  320.     case $? in
  321.     0)    echo "Done, the \"$FAX\" user should now have the right user id.";;
  322.     *) cat <<-EOF
  323.     Something went wrong; the command failed with:
  324.  
  325.     "$emsg1"
  326.  
  327.     The fax server will not work correctly until the proper uid
  328.     is setup for it in the password file.  Please fix this problem
  329.     and then rerun faxaddmodem.
  330.     EOF
  331.     exit 1
  332.     ;;
  333.     esac
  334. }
  335.  
  336. #
  337. # Add a fax user to the password file and lock the
  338. # entry so that noone can login as the user.
  339. #
  340. addFaxUser()
  341. {
  342.     emsg1=`addPasswd $FAX $faxUID $faxGID $SPOOL 2>&1`
  343.     case $? in
  344.     0)  emsg2=`lockPasswd $FAX 2>&1`
  345.     case $? in
  346.     0) echo "Added user \"$FAX\" to $PASSWD.";;
  347.     *) emsg3=`deletePasswd $FAX 2>&1`
  348.        case $? in
  349.        0|9) cat <<-EOF
  350.         Failed to add user "$FAX" to $PASSWD because the
  351.         attempt to lock the password failed with:
  352.  
  353.         "$emsg2"
  354.  
  355.         Please fix this problem and rerun this script."
  356.         EOF
  357.         exit 1
  358.         ;;
  359.        *)   cat <<-EOF
  360.         You will have to manually edit $PASSWD because
  361.         after successfully adding the new user "$FAX", the
  362.         attempt to lock its password failed with:
  363.  
  364.         "$emsg2"
  365.  
  366.         and the attempt to delete the insecure passwd entry failed with:
  367.  
  368.         "$emsg3"
  369.  
  370.         To close this security hole, you should add a password
  371.         to the "$FAX" entry in the file $PASSWD, or lock this
  372.         entry with an invalid password.
  373.         EOF
  374.         ;;
  375.         esac
  376.         exit 1;;
  377.     esac;;
  378.     9)  # fax was already in $PASSWD, but not found with grep
  379.     ;;
  380.     *)  cat <<-EOF
  381.     There was a problem adding user "$FAX" to $PASSWD;
  382.     the command failed with:
  383.  
  384.     "$emsg1"
  385.  
  386.     The fax server will not work until you have corrected this problem.
  387.     EOF
  388.     exit 1;;
  389.     esac
  390. }
  391.  
  392. x=`grep "^$FAX:" $PASSWD | cut -d: -f3`
  393. if [ -z "$x" ]; then
  394.     echo ""
  395.     echo "You do not appear to have a "$FAX" user in the password file."
  396.     prompt "The fax software needs this to work properly, add it [yes]?"
  397.     read x
  398.     if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
  399.     addFaxUser
  400.     fi
  401. elif [ "$x" != "$faxUID" ]; then
  402.     echo ""
  403.     echo "It looks like you have a \"$FAX\" user in the password file,"
  404.     echo "but with a uid different than the uid for uucp.  You probably"
  405.     echo "have old fax software installed.  In order for this software"
  406.     echo "to work properly, the fax user uid must be the same as uucp."
  407.     prompt "Is it ok to change the password entry for \"$FAX\" [yes]?"
  408.     read x
  409.     if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
  410.     fixupFaxUser
  411.     fi
  412. fi
  413. #
  414. # This should only have an effect on an SGI system...
  415. # hide the fax user from pandora & co.
  416. #
  417. if [ "$OS" = "IRIX" -a -f $SGIPASSWD ]; then
  418.     x=$FAX:noshow
  419.     grep $x $SGIPASSWD >/dev/null 2>&1 ||
  420.     (echo ""; echo "Adding fax user to \"$SGIPASSWD\"."; echo $x >>$SGIPASSWD)
  421. fi
  422.  
  423. #
  424. # Make sure a service entry is present.
  425. #
  426. hasYP=`ypcat services 2>/dev/null | tail -1` 2>/dev/null
  427. x=
  428. if [ "$hasYP" ]; then
  429.     x=`ypcat services 2>/dev/null | egrep '^(flex)?fax[     ]'` 2>/dev/null
  430.     if [ -z "$x" ]; then
  431.     echo ""
  432.     echo "There does not appear to be an entry for the fax service in the YP database;"
  433.     echo "the software will not work properly without one.  Contact your administrator"
  434.     echo "to get the folllowing entry added:"
  435.     echo ""
  436.     echo "fax    4557/tcp        # FAX transmission service"
  437.     echo ""
  438.     exit 1
  439.     fi
  440. else
  441.     x=`egrep '^(flex)?fax[     ]' $SERVICES 2>/dev/null` 2>/dev/null
  442.     if [ -z "$x" ]; then
  443.     echo ""
  444.     echo "There does not appear to be an entry for the fax service in the $SERVICES file;"
  445.     prompt "should an entry be added to $SERVICES [yes]?"
  446.     read x
  447.     if [ "$x" = "" -o "$x" = "y" -o "$x" = "yes" ]; then
  448.         echo "fax        4557/tcp        # FAX transmission service" >>$SERVICES
  449.     fi
  450.     fi
  451. fi
  452.  
  453. #
  454. # Check that inetd is setup to provide service.
  455. #
  456. E="fax    stream    tcp    nowait    $FAX    $SERVERDIR/faxd.recv    faxd.recv"
  457. test -f $INETDCONF && {
  458.     egrep "^(flex)?fax[     ]*stream[     ]*tcp" $INETDCONF >/dev/null 2>&1 ||
  459.     (echo ""
  460.      echo "There is no entry for the fax service in \"$INETDCONF\";"
  461.      prompt "should one be added [yes]?"
  462.      read x
  463.      if [ "$x" = "" -o "$x" = "y" -o "$x" = "yes" ]; then
  464.     echo "$E" >>$INETDCONF;
  465.     if killall -HUP inetd 2>/dev/null; then
  466.         echo "Poked inetd so that it re-reads the configuration file."
  467.     else
  468.         echo "Beware, you may need to send a HUP signal to inetd."
  469.     fi
  470.      fi
  471.     )
  472. }
  473.  
  474. #
  475. # Check for a FaxMaster entry for sending mail.
  476. #
  477. x=`ypcat -k aliases 2>/dev/null | grep -i '^faxmaster'` 2>/dev/null
  478. if [ -z "$x" -a -f $ALIASES ]; then
  479.     x=`grep -i '^faxmaster' $ALIASES`
  480. fi
  481. if [ -z "$x" ]; then
  482.     echo ""
  483.     echo "There does not appear to be an entry for the FaxMaster either in"
  484.     echo "the yellow pages database or in the $ALIASES file;"
  485.     prompt "should an entry be added to $ALIASES [yes]?"
  486.     read x
  487.     if [ "$x" = "" -o "$x" = "y" -o "$x" = "yes" ]; then
  488.     promptForNonNullStringParameter "${USER:-root}" \
  489.        "Users to receive fax-related mail"
  490.     (echo "# alias for notification messages from FlexFAX servers";
  491.      echo "FaxMaster: $param") >>$ALIASES
  492.     if newaliases 2>/dev/null; then
  493.         echo "Rebuilt $ALIASES database."
  494.     else
  495.         echo "Can not find newaliases to rebuild $ALIASES;"
  496.         echo "you will have to do it yourself."
  497.     fi
  498.     fi
  499. fi
  500.  
  501.  
  502. echo ""
  503. echo "Done verifying system setup."
  504. echo ""
  505. # End of system-related setup checking
  506.  
  507. while [ -z "$TTY" -o ! -c /dev/$TTY ]; do
  508.     if [ "$TTY" != "" ]; then
  509.     echo "/dev/$TTY is not a terminal device."
  510.     fi
  511.     prompt "Serial port that modem is connected to [$TTY]?"; read TTY
  512. done
  513.  
  514. JUNK="$OUT"
  515. trap "rm -f \$JUNK; exit 1" 0 1 2 15
  516.  
  517. if [ ! -d $LOCKDIR ]; then
  518.     prompt "Hmm, uucp lock files are not in \"$LOCKDIR\", where are they?"
  519.     read x
  520.     while [ ! -d $x ]; do
  521.     prompt "Nope, \"$x\" is not a directory; try again:"
  522.     read x
  523.     done
  524.     LOCKDIR=$x
  525. fi
  526.  
  527. #
  528. # Try to deduce if the tty devices are named in the SGI
  529. # sense (ttyd<port>, ttym<port>, and ttyf<port>) or the
  530. # way that everyone else seems to do it--tty<port>
  531. #
  532. # (I'm sure that someone will tell me there is another way as well.)
  533. #
  534. case "$OS" in
  535. IRIX)
  536.     PORT=`expr $TTY : 'tty.\(.*\)'`
  537.     for x in f m d; do
  538.     LOCKX="$LOCKX $LOCKDIR/LCK..tty$x${PORT}"
  539.     done
  540.     DEVS="/dev/ttyd${PORT} /dev/ttym${PORT} /dev/ttyf${PORT}"
  541.     #
  542.     # NB: we use ttyd* device names in the following
  543.     # work so that we are not stopped by a need for DCD.
  544.     #
  545.     tdev=/dev/ttyd${PORT}
  546.     #
  547.     # No current SGI equipment supports rates >38400
  548.     #
  549.     SPEEDS="38400 19200 9600 4800 2400 1200"
  550.     ;;
  551. BSDi|BSD/386|386bsd|386BSD)
  552.     PORT=`expr $TTY : 'com\(.*\)'`
  553.     LOCKX="$LOCKDIR/LCK..$TTY"
  554.     DEVS=/dev/$TTY
  555.     tdev=/dev/$TTY
  556.     ;;
  557. SunOS|Linux|ULTRIX|HP-UX|FreeBSD)
  558.     PORT=`expr $TTY : 'tty\(.*\)'`
  559.     LOCKX="$LOCKDIR/LCK..$TTY"
  560.     DEVS=/dev/$TTY
  561.     tdev=/dev/$TTY
  562.     ;;
  563. svr4)
  564.     PORT=`expr $TTY : 'term\/\(.*\)' \| $TTY`    # Usual
  565.     PORT=`expr $PORT : 'cua\/\(.*\)' \| $PORT`    # Solaris
  566.     PORT=`expr $PORT : 'tty\(.*\)' \| $PORT`    # Old-style
  567.     DEVS=/dev/$TTY
  568.     tdev=/dev/$TTY
  569.     LOCKX="$LOCKDIR/`$SVR4UULCKN $DEVS`" || {
  570.     echo "Sorry, I cannot determine the UUCP lock file name for $DEVS"
  571.     exit 1
  572.     }
  573.     ;;
  574. *)
  575.     echo "Beware, I am guessing the tty naming conventions on your system:"
  576.     PORT=`expr $TTY : 'tty\(.*\)'`;    echo "Serial port: $PORT"
  577.     LOCKX="$LOCKDIR/LCK..$TTY";        echo "UUCP lock file: $LOCKX"
  578.     DEVS=/dev/$TTY; tdev=/dev/$TTY;    echo "TTY device: $DEVS"
  579.     ;;
  580. esac
  581. DEVID="`echo $TTY | tr '/' '_'`"
  582. CONFIG=$CPATH.$DEVID
  583.  
  584. #
  585. # Check that device is not currently being used.
  586. #
  587. for x in $LOCKX; do
  588.     if [ -f $x ]; then
  589.     echo "Sorry, the device is currently in use by another program."
  590.     exit 1
  591.     fi
  592. done
  593.  
  594. #
  595. # Look for conflicting configuration stuff.
  596. #
  597. OLDCONFIG=""
  598.  
  599. checkPort()
  600. {
  601.     devID="`echo $1 | tr '/' '_'`"
  602.     if [ -f $CPATH.$devID -a -p $SPOOL/FIFO.$devID ]; then
  603.     echo "There appears to be a modem already setup on $devID,"
  604.     prompt "is this to be replaced [yes]?"
  605.     read x;
  606.     if [ "$x" = "n" -o "$x" = "no" ]; then
  607.         echo "Sorry, but you can not configure multiple servers on"
  608.         echo "the same serial port."
  609.         exit 1
  610.  
  611.     fi
  612.     echo "Removing old FIFO special file $SPOOL/FIFO.$devID."
  613.     $QUIT $devID >/dev/null 2>&1; rm -f $SPOOL/FIFO.$devID
  614.     OLDCONFIG=$CPATH.$devID
  615.     fi
  616. }
  617.  
  618. if [ "$OS" = "IRIX" ]; then
  619.     case $TTY in
  620.     ttym${PORT}) checkPort ttyd${PORT}; checkPort ttyf${PORT};;
  621.     ttyf${PORT}) checkPort ttym${PORT}; checkPort ttyd${PORT};;
  622.     ttyd${PORT}) checkPort ttym${PORT}; checkPort ttyf${PORT};;
  623.     esac
  624. fi
  625. $QUIT $DEVID >/dev/null 2>&1; sleep 1        # shutdown existing server
  626.  
  627. #
  628. # Lock the device for later use when deducing the modem type.
  629. #
  630. JUNK="$JUNK $LOCKX"
  631.  
  632. LOCKSTR=`expr "         $$" : '.*\(..........\)'`
  633. # lock the device by all of its names
  634. for x in $LOCKX; do
  635.     echo "$LOCKSTR" > $x
  636. done
  637. # zap any gettys or other users
  638. fuser -k $DEVS >/dev/null 2>&1 || {
  639.     cat<<EOF
  640. Hmm, there does not appear to be an fuser command on your machine.
  641. This means that I am unable to insure that all processes using the
  642. modem have been killed.  I will keep going, but beware that you may
  643. have competition for the modem.
  644. EOF
  645. }
  646.  
  647. cat<<EOF
  648.  
  649. Ok, time to setup a configuration file for the modem.  The manual
  650. page config(4F) may be useful during this process.  Also be aware
  651. that at any time you can safely interrupt this procedure.
  652.  
  653. EOF
  654.  
  655. getParameter()
  656. {
  657.     param=`grep "^$1:" $2 | sed -e 's/[     ]*#.*//' -e 's/.*:[     ]*//'`
  658. }
  659.  
  660. #
  661. # Get the server config values
  662. # from the prototype config file.
  663. #
  664. getServerProtoParameters()
  665. {
  666.     file=$1
  667.     getParameter FAXNumber $file;        protoFAXNumber="$param"
  668.     getParameter CountryCode $file;        protoCountryCode="$param"
  669.     getParameter AreaCode $file;        protoAreaCode="$param"
  670.     getParameter LongDistancePrefix $file;  protoLongDistancePrefix="$param"
  671.     getParameter InternationalPrefix $file; protoInternationalPrefix="$param"
  672.     getParameter DialStringRules $file;        protoDialStringRules="$param"
  673.     getParameter ServerTracing $file;        protoServerTracing="$param"
  674.     getParameter SessionTracing $file;        protoSessionTracing="$param"
  675.     getParameter RecvFileMode $file;        protoRecvFileMode="$param"
  676.     getParameter LogFileMode $file;        protoLogFileMode="$param"
  677.     getParameter DeviceMode $file;        protoDeviceMode="$param"
  678.     getParameter RingsBeforeAnswer $file;   protoRingsBeforeAnswer="$param"
  679.     getParameter SpeakerVolume $file;
  680.     # convert old numeric style
  681.     case "$param" in
  682.     0)    protoSpeakerVolume="off";;
  683.     1)    protoSpeakerVolume="low";;
  684.     2)    protoSpeakerVolume="quiet";;
  685.     3)    protoSpeakerVolume="medium";;
  686.     4)    protoSpeakerVolume="high";;
  687.     *)    protoSpeakerVolume="$param";;
  688.     esac
  689.     # convert old-style UseDialPrefix & DialingPrefix to ModemDialCmd fmt
  690.     getParameter UseDialPrefix $file;
  691.     case "$param" in
  692.     [yY]es|[oO]n) getParameter DialingPrefix $file; DialingPrefix="$param";;
  693.     *)                              DialingPrefix="";;
  694.     esac
  695.     # convert old-style GettyAllowed & GettySpeed to GettyArgs
  696.     getParameter GettyAllowed $file;
  697.     case "$param" in
  698.     [yY]es|[oO]n) getParameter GettySpeed $file; protoGettyArgs="$param";;
  699.     *)          getParameter GettyArgs $file;  protoGettyArgs="$param";;
  700.     esac
  701.     # convert old-style yes/no for QualifyTSI
  702.     getParameter QualifyTSI $file;
  703.     case "$param" in
  704.     [yY]es|[oO]n) protoQualifyTSI="etc/tsi";;
  705.     *)          protoQualifyTSI="$param";;
  706.     esac
  707.     getParameter JobReqBusy $file;    protoJobReqBusy="$param"
  708.     getParameter JobReqNoCarrier $file;    protoJobReqNoCarrier="$param"
  709.     getParameter JobReqNoAnswer $file;    protoJobReqNoAnswer="$param"
  710.     getParameter JobReqProto $file;    protoJobReqProto="$param"
  711.     getParameter JobReqOther $file;    protoJobReqOther="$param"
  712.     getParameter UUCPLockTimeout $file;    protoUUCPLockTimeout="$param"
  713.     getParameter PollModemWait $file;    protoPollModemWait="$param"
  714.     getParameter PollLockWait $file;    protoPollLockWait="$param"
  715. }
  716.  
  717. setupServerParameters()
  718. {
  719.     FAXNumber="$protoFAXNumber"
  720.     AreaCode="$protoAreaCode"
  721.     CountryCode="${protoCountryCode:-1}"
  722.     LongDistancePrefix="${protoLongDistancePrefix:-1}"
  723.     InternationalPrefix="${protoInternationalPrefix:-011}"
  724.     DialStringRules="${protoDialStringRules:-etc/dialrules}"
  725.     ServerTracing="${protoServerTracing:-1}"
  726.     SessionTracing="${protoSessionTracing:-11}"
  727.     RecvFileMode="${protoRecvFileMode:-0600}"
  728.     LogFileMode="${protoLogFileMode:-0600}"
  729.     DeviceMode="${protoDeviceMode:-0600}"
  730.     RingsBeforeAnswer="${protoRingsBeforeAnswer:-1}"
  731.     SpeakerVolume="${protoSpeakerVolume:-off}"
  732.     GettyArgs="$protoGettyArgs"
  733.     QualifyTSI="$protoQualifyTSI"
  734.     JobReqBusy="$protoJobReqBusy"
  735.     JobReqNoCarrier="$protoJobReqNoCarrier"
  736.     JobReqNoAnswer="$protoJobReqNoAnswer"
  737.     JobReqProto="$protoJobReqProto"
  738.     JobReqOther="$protoJobReqOther"
  739.     UUCPLockTimeout="$protoUUCPLockTimeout"
  740.     PollModemWait="$protoPollModemWait"
  741.     PollLockWait="$protoPollLockWait"
  742. }
  743.  
  744. #
  745. # Append a sed command to the ServerCmds if we need to
  746. # alter the existing configuration parameter.  Note that
  747. # we handle the case where there are embedded blanks or
  748. # tabs by enclosing the string in quotes.
  749. #
  750. addServerSedCmd()
  751. {
  752.     test "$1" != "$2" && {
  753.     # escape backslashes to counteract shell parsing and sed magic chars
  754.     x=`echo "$2" | sed 's/[&\\\\"]/\\\\&/g'`
  755.     if [ `expr "$2" : "[^\"].*[ ]"` = 0 ]; then
  756.         ServerCmds="$ServerCmds -e '/^$3:/s;\(:[     ]*\).*;\1$x;'"
  757.     else
  758.         ServerCmds="$ServerCmds -e '/^$3:/s;\(:[     ]*\).*;\1\"$x\";'"
  759.     fi
  760.     }
  761. }
  762.  
  763. #
  764. # Setup the sed commands for crafting the configuration file:
  765. #
  766. makeSedServerCommands()
  767. {
  768.     ServerCmds=""
  769.     addServerSedCmd "$protoFAXNumber"        "$FAXNumber"    FAXNumber
  770.     addServerSedCmd "$protoAreaCode"        "$AreaCode"    AreaCode
  771.     addServerSedCmd "$protoCountryCode"        "$CountryCode"    CountryCode
  772.     addServerSedCmd "$protoLongDistancePrefix"    "$LongDistancePrefix" \
  773.     LongDistancePrefix
  774.     addServerSedCmd "$protoInternationalPrefix"    "$InternationalPrefix" \
  775.     InternationalPrefix
  776.     addServerSedCmd "$protoDialStringRules"    "$DialStringRules" \
  777.     DialStringRules
  778.     addServerSedCmd "$protoServerTracing"    "$ServerTracing" \
  779.     ServerTracing
  780.     addServerSedCmd "$protoSessionTracing"    "$SessionTracing" \
  781.     SessionTracing
  782.     addServerSedCmd "$protoRecvFileMode"    "$RecvFileMode"    RecvFileMode
  783.     addServerSedCmd "$protoLogFileMode"        "$LogFileMode"    LogFileMode
  784.     addServerSedCmd "$protoDeviceMode"        "$DeviceMode"    DeviceMode
  785.     addServerSedCmd "$protoRingsBeforeAnswer"    "$RingsBeforeAnswer" \
  786.     RingsBeforeAnswer
  787.     addServerSedCmd "$protoSpeakerVolume"    "$SpeakerVolume" \
  788.     SpeakerVolume
  789.     addServerSedCmd "$protoGettyArgs"        "$GettyArgs"    GettyArgs
  790.     addServerSedCmd "$protoQualifyTSI"        "$QualifyTSI"    QualifyTSI
  791.     addServerSedCmd "$protoJobReqBusy"        "$JobReqBusy" \
  792.        JobReqBusy
  793.     addServerSedCmd "$protoJobReqNoCarrier"    "$JobReqNoCarrier" \
  794.     JobReqNoCarrier
  795.     addServerSedCmd "$protoJobReqNoAnswer"    "$JobReqNoAnswer" \
  796.     JobReqNoAnswer
  797.     addServerSedCmd "$protoJobReqProto"        "$JobReqProto" \
  798.        JobReqProto
  799.     addServerSedCmd "$protoJobReqOther"        "$JobReqOther" \
  800.        JobReqOther
  801.     addServerSedCmd "$protoUUCPLockTimeout"    "$UUCPLockTimeout" \
  802.     UUCPLockTimeout
  803.     addServerSedCmd "$protoPollModemWait"    "$PollModemWait" \
  804.     PollModemWait
  805.     addServerSedCmd "$protoPollLockWait"    "$PollLockWait" \
  806.        PollLockWait
  807. }
  808.  
  809. #
  810. # Prompt the user for volume setting.
  811. #
  812. promptForSpeakerVolume()
  813. {
  814.     x=""
  815.     while [ -z "$x" ]; do
  816.     prompt "Modem speaker volume [$SpeakerVolume]?"; read x
  817.     if [ "$x" != "" ]; then
  818.         # strip leading and trailing white space
  819.         x=`echo "$x" | sed -e 's/^[     ]*//' -e 's/[     ]*$//'`
  820.         case "$x" in
  821.         [oO]*)    x="off";;
  822.         [lL]*)    x="low";;
  823.         [qQ]*)    x="quiet";;
  824.         [mM]*)    x="medium";;
  825.         [hH]*)    x="high";;
  826.         *)
  827. cat <<EOF
  828.  
  829. "$x" is not a valid speaker volume setting; use one
  830. of: "off", "low", "quiet", "medium", and "high".
  831. EOF
  832.         x="";;
  833.         esac
  834.     else
  835.         x="$SpeakerVolume"
  836.     fi
  837.     done
  838.     SpeakerVolume="$x"
  839. }
  840.  
  841. #
  842. # Verify that the fax number, area code, and country
  843. # code jibe.  Perhaps this is too specific to the USA?
  844. #
  845. checkFaxNumber()
  846. {
  847.     pat="[\"]*\+$CountryCode[-. ]*$AreaCode[-. ]*[0-9][- .0-9]*[\"]*"
  848.     match=`expr "$FAXNumber" : "\($pat\)"`
  849.     if [ "$match" != "$FAXNumber" ]; then
  850.     cat<<EOF
  851.  
  852. Your facsimile phone number ($FAXNumber) does not agree with your
  853. country code ($CountryCode) or area code ($AreaCode).  The number
  854. should be a fully qualified international dialing number of the form:
  855.  
  856.     +$CountryCode $AreaCode <local phone number>
  857.  
  858. Spaces, hyphens, and periods can be included for legibility.  For example,
  859.  
  860.     +$CountryCode.$AreaCode.555.1212
  861.  
  862. is a possible phone number (using your country and area codes).
  863. EOF
  864.     ok="no";
  865.     fi
  866. }
  867.  
  868. #
  869. # Verify that a number is octal and if not, add a prefixing "0".
  870. #
  871. checkOctalNumber()
  872. {
  873.     param=$1
  874.     if [ "`expr "$param" : '\(.\)'`" != "0" ]; then
  875.     param="0${param}"
  876.     return 0
  877.     else
  878.     return 1
  879.     fi
  880. }
  881.  
  882. #
  883. # Verify that the dial string rules file exists.
  884. #
  885. checkDialStringRules()
  886. {
  887.     if [ ! -f $SPOOL/$DialStringRules ]; then
  888.     cat<<EOF
  889.  
  890. Warning, the dial string rules file,
  891.  
  892.     $SPOOL/$DialStringRules
  893.  
  894. does not exist, or is not a plain file.  The rules file
  895. must reside in the $SPOOL directory tree.
  896. EOF
  897.     ok="no";
  898.     fi
  899. }
  900.  
  901. #
  902. # Print the current server configuration parameters.
  903. #
  904. printServerConfig()
  905. {
  906.     cat<<EOF
  907.  
  908. The server configuration parameters are:
  909.  
  910. AreaCode:        $AreaCode
  911. CountryCode:        $CountryCode
  912. FAXNumber:        $FAXNumber
  913. LongDistancePrefix:    $LongDistancePrefix
  914. InternationalPrefix:    $InternationalPrefix
  915. DialStringRules:    $DialStringRules
  916. ServerTracing:        $ServerTracing
  917. SessionTracing:        $SessionTracing
  918. RecvFileMode:        $RecvFileMode
  919. LogFileMode:        $LogFileMode
  920. DeviceMode:        $DeviceMode
  921. RingsBeforeAnswer:    $RingsBeforeAnswer
  922. SpeakerVolume:        $SpeakerVolume
  923. EOF
  924.     test "$protoGettyArgs" &&
  925.     echo "GettyArgs:        $GettyArgs"
  926.     test "$protoQualifyTSI" &&
  927.     echo "QualifyTSI:        $QualifyTSI"
  928.     test "$protoJobReqBusy" &&
  929.     echo "JobReqBusy:        $JobReqBusy"
  930.     test "$protoJobReqNoCarrier" &&
  931.     echo "JobReqNoCarrier:    $JobReqNoCarrier"
  932.     test "$protoJobReqNoAnswer" &&
  933.     echo "JobReqNoAnswer:        $JobReqNoAnswer"
  934.     test "$protoJobReqProto" &&
  935.     echo "JobReqProto:        $JobReqProto"
  936.     test "$protoJobReqOther" &&
  937.     echo "JobReqOther:        $JobReqOther"
  938.     test "$protoUUCPLockTimeout" &&
  939.     echo "UUCPLockTimeout:    $UUCPLockTimeout"
  940.     test "$protoPollModemWait" &&
  941.     echo "PollModemWait:        $PollModemWait"
  942.     test "$protoPollLockWait" &&
  943.     echo "PollLockWait:        $PollLockWait"
  944.     echo ""
  945. }
  946.  
  947. if [ -f $CONFIG -o -z "$OLDCONFIG" ]; then
  948.     OLDCONFIG=$CONFIG
  949. fi
  950. if [ -f $OLDCONFIG ]; then
  951.     echo "Hey, there is an existing config file "$OLDCONFIG"..."
  952.     getServerProtoParameters $OLDCONFIG
  953.     ok="skip"                # skip prompting first time through
  954. else
  955.     echo "No existing configuration, let's do this from scratch."
  956.     echo ""
  957.     getServerProtoParameters $CPATH.skel # get from skeletal file
  958.     ok="prompt"                # prompt for parameters
  959. fi
  960. setupServerParameters            # record prototype & setup defaults
  961.  
  962. if [ -z "$FAXNumber" ]; then
  963.     FAXNumber="+$CountryCode $AreaCode 555-1212"
  964. fi
  965. #
  966. # Prompt user for server-related configuration parameters
  967. # and do consistency checking on what we get.
  968. #
  969. while [ "$ok" != "" -a "$ok" != "y" -a "$ok" != "yes" ]; do
  970.     if [ "$ok" != "skip" ]; then
  971.     promptForNumericParameter "$CountryCode" \
  972.         "Country code"; CountryCode=$param;
  973.     promptForNumericParameter "$AreaCode" \
  974.         "Area code"; AreaCode=$param;
  975.     promptForNonNullStringParameter "$FAXNumber" \
  976.         "Phone number of fax modem"; FAXNumber=$param;
  977.     promptForNumericParameter "$LongDistancePrefix" \
  978.         "Long distance dialing prefix"; LongDistancePrefix=$param;
  979.     promptForNumericParameter "$InternationalPrefix" \
  980.         "International dialing prefix"; InternationalPrefix=$param;
  981.     promptForNonNullStringParameter "$DialStringRules" \
  982.         "Dial string rules file"; DialStringRules=$param;
  983.     promptForCStyleNumericParameter "$ServerTracing" \
  984.         "Tracing during normal server operation"; ServerTracing=$param;
  985.     promptForCStyleNumericParameter "$SessionTracing" \
  986.         "Tracing during send and receive sessions"; SessionTracing=$param;
  987.     promptForNumericParameter "$RecvFileMode" \
  988.         "Protection mode for received facsimile"; RecvFileMode=$param;
  989.     promptForNumericParameter "$LogFileMode" \
  990.         "Protection mode for session logs"; LogFileMode=$param;
  991.     promptForNumericParameter "$DeviceMode" \
  992.         "Protection mode for $TTY"; DeviceMode=$param;
  993.     promptForNumericParameter "$RingsBeforeAnswer" \
  994.         "Rings to wait before answering"; RingsBeforeAnswer=$param;
  995.     promptForSpeakerVolume;
  996.     test "$protoGettyArgs" && {
  997.         promptForNonNullStringParameter "$GettyArgs" \
  998.         "Command line arguments to getty program"; GettyArgs="$param";
  999.     }
  1000.     test "$protoQualifyTSI"    && {
  1001.         promptForNonNullStringParameter "$QualifyTSI" \
  1002.         "Relative pathname of TSI patterns file";
  1003.         QualifyTSI="$param";
  1004.     }
  1005.     test "$protoJobReqBusy"    && {
  1006.         promptForCStyleNumericParameter "$JobReqBusy" \
  1007.         "Job requeue interval on BUSY status (secs)";
  1008.         JobReqBusy=$param;
  1009.     }
  1010.     test "$protoJobReqNoCarrier" && {
  1011.         promptForCStyleNumericParameter "$JobReqNoCarrier" \
  1012.         "Job requeue interval on NO CARRIER status (secs)";
  1013.         JobReqNoCarrier=$param;
  1014.     }
  1015.     test "$protoJobReqNoAnswer" && {
  1016.         promptForCStyleNumericParameter "$JobReqNoAnswer" \
  1017.         "Job requeue interval on NO ANSWER status (secs)";
  1018.         JobReqNoAnswer=$param;
  1019.     }
  1020.     test "$protoJobReqProto" && {
  1021.         promptForCStyleNumericParameter "$JobReqProto" \
  1022.         "Job requeue interval on protocol error (secs)";
  1023.         JobReqProto=$param;
  1024.     }
  1025.     test "$protoJobReqOther" && {
  1026.         promptForCStyleNumericParameter "$JobReqOther" \
  1027.         "Job requeue interval for \"other\" sorts of problems (secs)";
  1028.         JobReqOther=$param;
  1029.     }
  1030.     test "$protoUUCPLockTimeout" && {
  1031.         promptForCStyleNumericParameter "$UUCPLockTimeout" \
  1032.         "UUCP lock file timeout (secs)";
  1033.         UUCPLockTimeout=$param;
  1034.     }
  1035.     test "$protoPollModemWait" && {
  1036.         promptForCStyleNumericParameter "$PollModemWait" \
  1037.         "Polling interval for modem-wait state (secs)";
  1038.         PollModemWait=$param;
  1039.     }
  1040.     test "$protoPollLockWait" && {
  1041.         promptForCStyleNumericParameter "$PollLockWait" \
  1042.         "Polling interval for lock-wait state (secs)";
  1043.         PollLockWait=$param;
  1044.     }
  1045.     fi
  1046.     checkOctalNumber $RecvFileMode &&    RecvFileMode=$param
  1047.     checkOctalNumber $LogFileMode &&    LogFileMode=$param
  1048.     checkOctalNumber $DeviceMode &&    DeviceMode=$param
  1049.     checkDialStringRules;
  1050.     checkFaxNumber;
  1051.     printServerConfig; prompt "Are these ok [yes]?"; read ok
  1052. done
  1053.  
  1054. #
  1055. # We've got all the server-related parameters, now for the modem ones.
  1056. #
  1057.  
  1058. cat<<EOF
  1059.  
  1060. Now we are going to probe the tty port to figure out the type
  1061. of modem that is attached.  This takes a few seconds, so be patient.
  1062. Note that if you do not have the modem cabled to the port, or the
  1063. modem is turned off, this may hang (just go and cable up the modem
  1064. or turn it on, or whatever).
  1065. EOF
  1066.  
  1067. if [ $OS = "SunOS" ]; then
  1068.     #
  1069.     # Sun systems have a command for manipulating software
  1070.     # carrier on a terminal line.  Set or reset carrier
  1071.     # according to the type of tty device being used.
  1072.     #
  1073.     case $TTY in
  1074.     tty*) ttysoftcar -y $TTY;;
  1075.     cua*) ttysoftcar -n $TTY;;
  1076.     esac
  1077. fi
  1078.  
  1079. if [ -x ${ONDELAY} ]; then
  1080.     onDev() {
  1081.     if [ "$1" = "-c" ]; then
  1082.         shift; catpid=`${ONDELAY} $tdev sh -c "$* >$OUT" & echo $!`
  1083.     else
  1084.         ${ONDELAY} $tdev sh -c "$*"
  1085.     fi
  1086.     }
  1087. else
  1088. cat<<'EOF'
  1089.  
  1090. The "ondelay" program to open the device without blocking is not
  1091. present.  We're going to try to continue without it; let's hope that
  1092. the serial port won't block waiting for carrier...
  1093. EOF
  1094.     onDev() {
  1095.     if [ "$1" = "-c" ]; then
  1096.         shift; catpid=`sh <$tdev >$tdev -c "$* >$OUT" & echo $!`
  1097.     else
  1098.         sh <$tdev >$tdev -c "$*"
  1099.     fi
  1100.     }
  1101. fi
  1102.  
  1103. case $OS in
  1104. *bsd*|*BSD*)    STTY="stty -f $tdev";;
  1105. *)        STTY=stty;;
  1106. esac
  1107.  
  1108. #
  1109. # Send each command in SendString to the modem and collect
  1110. # the result in $OUT.  Read this very carefully.  It's got
  1111. # a lot of magic in it!
  1112. #
  1113. SendToModem()
  1114. {
  1115.     onDev $STTY 0                # reset the modem (hopefully)
  1116.     onDev -c "$STTY clocal && exec $CAT $tdev"    # start listening for output
  1117.     sleep 3                    # let listener open dev first
  1118.     onDev $STTY -echo -icrnl -ixon -ixoff -isig clocal $SPEED; sleep 1
  1119.     # NB: merging \r & ATQ0 causes some modems problems
  1120.     printf "\r" >$tdev; sleep 1;        # force consistent state
  1121.     printf "ATQ0V1E1\r" >$tdev; sleep 1;    # enable echo and result codes
  1122.     for i in $*; do
  1123.     printf "$i\r" >$tdev; sleep 1;
  1124.     done
  1125.     kill -9 $catpid; catpid=
  1126.     # NB: [*&\\\\$] must have the "$" last for AIX (yech)
  1127.     pat=`echo "$i"|sed -e 's/[*&\\\\$]/\\\\&/g'` # escape regex metacharacters
  1128.     RESPONSE=`tr -d '\015' < $OUT | \
  1129.     sed -n "/$pat/{n;s/ *$//;p;q;}" | sed 's/+F.*=//'`
  1130. }
  1131.  
  1132. echo ""
  1133. if [ -z "$SPEED" ]; then
  1134.     #
  1135.     # Probe for the highest speed at which the modem
  1136.     # responds to "AT" with "OK".
  1137.     #
  1138.     printf "Probing for best speed to talk to modem:"
  1139.     for SPEED in $SPEEDS
  1140.     do
  1141.     printf " $SPEED"
  1142.     SendToModem "AT" >/dev/null 2>&1
  1143.     sleep 1
  1144.     RESULT=`tr -d "\015" < $OUT | tail -1`
  1145.     test "$RESULT" = "OK" && break;
  1146.     done
  1147.     if [ "$RESULT" != "OK" ]; then
  1148.     echo ""
  1149.     echo "Unable to deduce DTE-DCE speed; check that you are using the"
  1150.     echo "correct device and/or that your modem is setup properly.  If"
  1151.     echo "all else fails, try the -s option to lock the speed."
  1152.     exit 1
  1153.     fi
  1154.     echo " OK."
  1155. else
  1156.     echo "Using user-specified $SPEED to talk to modem."
  1157. fi
  1158. RESULT="";
  1159. while [ -z "$RESULT" ]; do
  1160.     #
  1161.     # This goes in the background while we try to
  1162.     # reset the modem.  If something goes wrong, it'll
  1163.     # nag the user to check on the problem.
  1164.     #
  1165.     (trap 0 1 2 15;
  1166.      while true; do
  1167.     sleep 10;
  1168.     echo ""
  1169.     echo "Hmm, something seems to be hung, check your modem eh?"
  1170.      done)& nagpid=$!
  1171.     trap "rm -f \$JUNK; kill $nagpid \$catpid; exit 1" 0 1 2 15
  1172.  
  1173.     SendToModem "AT+FCLASS=?"             # ask for class support
  1174.  
  1175.     kill $nagpid
  1176.     trap "rm -f \$JUNK; test \"\$catpid\" && kill \$catpid; exit 1" 0 1 2 15
  1177.     sleep 1
  1178.  
  1179.     RESULT=`tr -d "\015" < $OUT | tail -1`
  1180.     if [ -z "$RESPONSE" ]; then
  1181.     echo ""
  1182.     echo "There was no response from the modem.  Perhaps the modem is"
  1183.     echo "turned off or the cable between the modem and host is not"
  1184.     echo "connected.  Please check the modem and hit a carriage return"
  1185.     prompt "when you are ready to try again:"
  1186.     read x
  1187.     fi
  1188. done
  1189.  
  1190. ModemType="" Manufacturer="" Model="" ProtoType="config.skel"
  1191.  
  1192. #
  1193. # Select a configuration file for a modem based on the
  1194. # deduced modem type.  Each routine below sends a set
  1195. # of commands to the modem to figure out the modem model
  1196. # and manufacturer and then compares them against the
  1197. # set of known values in associated config files.
  1198. # Note that this is done with a tricky bit of shell
  1199. # hacking--generating a case statement that is then
  1200. # eval'dwith the result being the setup of the
  1201. # ProtoType shell variable.
  1202. #
  1203. configureClass2Modem()
  1204. {
  1205.     ModemType=Class2
  1206.     echo "Hmm, this looks like a Class 2 modem."
  1207.  
  1208.     SendToModem "AT+FCLASS=2" "AT+FMFR?"
  1209.     Manufacturer=$RESPONSE
  1210.     echo "Modem manufacturer is \"$Manufacturer\"."
  1211.  
  1212.     SendToModem "AT+FCLASS=2" "AT+FMDL?"
  1213.     Model=$RESPONSE
  1214.     echo "Modem model is \"$Model\"."
  1215.  
  1216.     eval `(cd $MODEMCONFIG; \
  1217.     grep 'CONFIG:[     ]*CLASS2' config.* |\
  1218.     awk -F: '
  1219.         BEGIN { print "case \"$Manufacturer-$Model\" in" }
  1220.         { print $4 ") ProtoType=" $1 ";;" }
  1221.         END { print "*) ProtoType=config.class2;;"; print "esac" }
  1222.     ')`
  1223. }
  1224.  
  1225. #
  1226. # As above, but for Class 2.0 modems.
  1227. #
  1228. configureClass2dot0Modem()
  1229. {
  1230.     ModemType=Class20
  1231.     echo "Hmm, this looks like a Class 2.0 modem."
  1232.     #
  1233.     SendToModem "AT+FCLASS=2.0" "AT+FMI?"
  1234.     Manufacturer=$RESPONSE
  1235.     echo "Modem manufacturer is \"$Manufacturer\"."
  1236.  
  1237.     SendToModem "AT+FCLASS=2.0" "AT+FMM?"
  1238.     Model=$RESPONSE
  1239.     echo "Modem model is \"$Model\"."
  1240.  
  1241.     eval `(cd $MODEMCONFIG; \
  1242.     grep 'CONFIG:[     ]*CLASS2.0' config.* |\
  1243.     awk -F: '
  1244.         BEGIN { print "case \"$Manufacturer-$Model\" in" }
  1245.         { print $4 ") ProtoType=" $1 ";;" }
  1246.         END { print "*) ProtoType=config.class2.0;;"; print "esac" }
  1247.     ')`
  1248. }
  1249.  
  1250. #
  1251. # Class 1 modems are handled a bit differently as
  1252. # there are no commands to obtain the manufacturer
  1253. # and model.  Instead we use ATI0 to get the product
  1254. # code and then compare it against the set of known
  1255. # values in the config files.
  1256. #
  1257. configureClass1Modem()
  1258. {
  1259.     ModemType=Class1 Manufacturer=Unknown Model=Unknown
  1260.     echo "Hmm, this looks like a Class 1 modem."
  1261.  
  1262.     SendToModem "ATI0"
  1263.     echo "Product code is \"$RESPONSE\"."
  1264.  
  1265.     eval `(cd $MODEMCONFIG; grep 'CONFIG:[     ]*CLASS1' config.*) |\
  1266.     sed 's/:[     ]*/:/g' |\
  1267.     awk -F: '
  1268. BEGIN    { proto = "" }
  1269. $4 == C    { if (proto != "") {
  1270.           print "echo \"Warning, multiple configuration files exist for this modem,\";"
  1271.           print "echo \"   the file " $1 " is ignored.\";"
  1272.       } else
  1273.           proto = $1 " " $5;
  1274.     }
  1275. END    { if (proto == "")
  1276.           proto = "config.class1"
  1277.       print "ProtoType=" proto
  1278.     }
  1279.     ' C="$RESPONSE" -`
  1280.     echo "Modem manufacturer is \"$Manufacturer\"."
  1281.     echo "Modem model is \"$Model\"."
  1282. }
  1283.  
  1284. configureClass1and2Modem()
  1285. {
  1286.     echo "This modem looks to have support for both Class 1 and 2;"
  1287.     prompt "how should it be configured [2]?"
  1288.     x=""
  1289.     while [ "$x" != "1" -a "$x" != "2" ]; do
  1290.     read x
  1291.     case "$x" in
  1292.     1|2)    ;;
  1293.     ?*)    echo ""
  1294.             prompt "Configure as Class 1 or 2 [2]?";;
  1295.     *)    x="2";;
  1296.     esac
  1297.     done
  1298.     echo ""
  1299.     case $x in
  1300.     1) configureClass1Modem;;
  1301.     2) configureClass2Modem;;
  1302.     esac
  1303. }
  1304.  
  1305. configureClass1and2dot0Modem()
  1306. {
  1307.     echo "This modem looks to have support for both Class 1 and 2.0;"
  1308.     prompt "how should it be configured [2.0]?"
  1309.     x=""
  1310.     while [ "$x" != "1" -a "$x" != "2.0" ]; do
  1311.     read x
  1312.     case "$x" in
  1313.     1|2.0)    ;;
  1314.     ?*)    echo ""
  1315.             prompt "Configure as Class 1 or 2.0 [2.0]?";;
  1316.     *)    x="2.0";;
  1317.     esac
  1318.     done
  1319.     echo ""
  1320.     case $x in
  1321.     1)   configureClass1Modem;;
  1322.     2.0) configureClass2dot0Modem;;
  1323.     esac
  1324. }
  1325.  
  1326. configureClass2and2dot0Modem()
  1327. {
  1328.     echo "This modem looks to have support for both Class 2 and 2.0;"
  1329.     prompt "how should it be configured [2.0]?"
  1330.     x=""
  1331.     while [ "$x" != "2" -a "$x" != "2.0" ]; do
  1332.     read x
  1333.     case "$x" in
  1334.     2|2.0)    ;;
  1335.     ?*)    echo ""
  1336.             prompt "Configure as Class 2 or 2.0 [2.0]?";;
  1337.     *)    x="2.0";;
  1338.     esac
  1339.     done
  1340.     echo ""
  1341.     case $x in
  1342.     2)   configureClass2Modem;;
  1343.     2.0) configureClass2dot0Modem;;
  1344.     esac
  1345. }
  1346.  
  1347. configureClass1and2and2dot0Modem()
  1348. {
  1349.     echo "This modem looks to have support for both Class 1, 2 and 2.0;"
  1350.     prompt "how should it be configured [2.0]?"
  1351.     x=""
  1352.     while [ "$x" != "1" -a "$x" != "2" -a "$x" != "2.0" ]; do
  1353.     read x
  1354.     case "$x" in
  1355.     1|2|2.0)    ;;
  1356.     ?*)    echo ""
  1357.             prompt "Configure as Class 1, 2 or 2.0 [2.0]?";;
  1358.     *)    x="2.0";;
  1359.     esac
  1360.     done
  1361.     echo ""
  1362.     case $x in
  1363.     1)   configureClass1Modem;;
  1364.     2)   configureClass2Modem;;
  1365.     2.0) configureClass2dot0Modem;;
  1366.     esac
  1367. }
  1368.  
  1369. giveup()
  1370. {
  1371.     cat<<EOF
  1372.  
  1373. We were unable to deduce what type of modem you have.  This means that
  1374. it did not respond as a Class 1, Class 2, or Class 2.0 modem should and
  1375. it did not appear as though it was an Abaton 24/96 (as made by Everex).
  1376. If you believe that your modem conforms to the Class 1, Class 2, or
  1377. Class 2.0 interface specification, or is an Abaton modem, then check
  1378. that the modem is operating properly and that you can communicate with
  1379. the modem from the host.  If your modem is not one of the above types
  1380. of modems, then this software does not support it and you will need to
  1381. write a driver that supports it.
  1382.  
  1383. EOF
  1384.     exit 1
  1385. }
  1386.  
  1387. echo ""
  1388. if [ "$RESULT" = "OK" ]; then
  1389.     # Looks like a Class 1, 2, or 2.0 modem, get more information
  1390.     case "`echo $RESPONSE | sed -e 's/[()]//g'`" in
  1391.     1)            configureClass1Modem;;
  1392.     2)            configureClass2Modem;;
  1393.     2.0)        configureClass2dot0Modem;;
  1394.     0,1)        configureClass1Modem;;
  1395.     0,2)        configureClass2Modem;;
  1396.     0,2.0)        configureClass2dot0Modem;;
  1397.     1,2)        configureClass1and2Modem;;
  1398.     1,2.0)        configureClass1and2dot0Modem;;
  1399.     2,2.0)        configureClass2and2dot0Modem;;
  1400.     0,1,2)        configureClass1and2Modem;;
  1401.     0,1,2.0)        configureClass1and2dot0Modem;;
  1402.     0,2,2.0)        configureClass2and2dot0Modem;;
  1403.     1,2,2.0)        configureClass1and2and2dot0Modem;;
  1404.     0,1,2,2.0)        configureClass1and2and2dot0Modem;;
  1405.     0,1,2,2.0,*)    configureClass1and2and2dot0Modem;;
  1406.     1,2,2.0,*)        configureClass1and2and2dot0Modem;;
  1407.     0,2,2.0,*)        configureClass2and2dot0Modem;;
  1408.     0,1,2.0,*)        configureClass1and2dot0Modem;;
  1409.     0,1,2,*)        configureClass1and2Modem;;
  1410.     2,2.0,*)        configureClass2and2dot0Modem;;
  1411.     1,2.0,*)        configureClass1and2dot0Modem;;
  1412.     1,2,*)        configureClass1and2Modem;;
  1413.     0,2.0,*)        configureClass2dot0Modem;;
  1414.     0,2,*)        configureClass2Modem;;
  1415.     0,1,*)        configureClass1Modem;;
  1416.     2.0,*)        configureClass2dot0Modem;;
  1417.     2,*)        configureClass2Modem;;
  1418.     1,*)        configureClass1Modem;;
  1419.     *)
  1420.     echo "The result of the AT+FCLASS=? command was:"
  1421.     echo ""
  1422.     cat $OUT
  1423.     giveup
  1424.     ;;
  1425.     esac
  1426. else
  1427.     echo "This not a Class 1, 2, or 2.0 modem,"
  1428.     echo "lets check some other possibilities..."
  1429.  
  1430.     SendToModem "ATI4?"
  1431.     RESULT=`tr -d "\015" < $OUT | tail -1`
  1432.     echo ""
  1433.     if [ "$RESULT" != "OK" ]; then
  1434.     echo "The modem does not seem to understand the ATI4? query."
  1435.     echo "Sorry, but I can't figure out how to configure this one."
  1436.     exit 1
  1437.     fi
  1438.     case "$RESPONSE" in
  1439.     EV968*|EV958*)
  1440.     ModemType="Abaton";
  1441.     echo "Hmm, this looks like an Abaton 24/96 (specifically a $RESPONSE)."
  1442.     ;;
  1443.     *)    echo "The result of the ATI4? query was:"
  1444.     echo ""
  1445.     cat $OUT
  1446.     giveup;
  1447.     ;;
  1448.     esac
  1449. fi
  1450.  
  1451. echo ""
  1452. #
  1453. # Given a modem type, manufacturer and model, select
  1454. # a prototype configuration file to work from.
  1455. #
  1456. case $ModemType in
  1457. Class1|Class2*)
  1458.     echo "Using prototype configuration file $ProtoType..."
  1459.     ;;
  1460. Abaton)
  1461.     echo "Using prototype Abaton 24/96 configuration file..."
  1462.     ProtoType=config.abaton
  1463.     ;;
  1464. esac
  1465.  
  1466. proto=$MODEMCONFIG/$ProtoType
  1467. if [ ! -f $proto ]; then
  1468.    cat<<EOF
  1469. Uh oh, I can't find the prototype file
  1470.  
  1471. "$proto"
  1472.  
  1473. EOF
  1474.     if [ "$ProtoType" != "config.skel" ]; then
  1475.         prompt "Do you want to continue using the skeletal configuration file [yes]?"
  1476.         read x
  1477.         if [ "$x" = "n" -o "$x" = "no" ]; then
  1478.        exit 1
  1479.     fi
  1480.     ProtoType="config.skel";
  1481.     proto=$MODEMCONFIG/$ProtoType;
  1482.     if [ ! -f $proto ]; then
  1483.         cat<<EOF
  1484. Sigh, the skeletal configuration file is not available either.  There
  1485. is not anything that I can do without some kind of prototype config
  1486. file; I'm bailing out..."
  1487. EOF
  1488.         exit 1
  1489.     fi
  1490.     else
  1491.     echo "There is nothing more that I can do; I'm bailing out..."
  1492.     exit 1
  1493.     fi
  1494. fi
  1495.  
  1496. #
  1497. # Prompt the user for an AT-style command.
  1498. #
  1499. promptForATCmdParameter()
  1500. {
  1501.     prompt "$2 [$1]?"; read x
  1502.     if [ "$x" ]; then
  1503.     # strip leading and trailing white space,
  1504.     # quote marks, and any prefacing AT; redouble
  1505.     # any backslashes lost through shell processing
  1506.     x=`echo "$x" | \
  1507.         sed -e 's/^[     ]*//' -e 's/[     ]*$//' -e 's/\"//g' | \
  1508.         sed -e 's/^[aA][tT]//' -e 's/\\\\/&&/g'`
  1509.     else
  1510.     x="$1"
  1511.     fi
  1512.     param="$x"
  1513. }
  1514.  
  1515. #
  1516. # Prompt the user for a boolean value.
  1517. #
  1518. promptForBooleanParameter()
  1519. {
  1520.     x=""
  1521.     while [ -z "$x" ]; do
  1522.     prompt "$2 [$1]?"; read x
  1523.     if [ "$x" ]; then
  1524.         # strip leading and trailing white space
  1525.         x=`echo "$x" | sed -e 's/^[     ]*//' -e 's/[     ]*$//'`
  1526.         case "$x" in
  1527.         n|no|off)    x="no";;
  1528.         y|yes|on)    x="yes";;
  1529.         *)
  1530. cat <<EOF
  1531.  
  1532. "$x" is not a valid boolean parameter setting;
  1533. use one of: "yes", "on", "no", or "off".
  1534. EOF
  1535.         x="";;
  1536.         esac
  1537.     else
  1538.         x="$1"
  1539.     fi
  1540.     done
  1541.     param="$x"
  1542. }
  1543.  
  1544. #
  1545. # Prompt the user for a bit order.
  1546. #
  1547. promptForBitOrderParameter()
  1548. {
  1549.     x=""
  1550.     while [ -z "$x" ]; do
  1551.     prompt "$2 [$1]?"; read x
  1552.     if [ "$x" ]; then
  1553.         # strip leading and trailing white space
  1554.         x=`echo "$x" | sed -e 's/^[     ]*//' -e 's/[     ]*$//'`
  1555.         case "$x" in
  1556.         [lL]*)    x="LSB2MSB";;
  1557.         [mM]*)    x="MSB2LSB";;
  1558.         *)
  1559. cat <<EOF
  1560.  
  1561. "$x" is not a valid bit order parameter setting; use
  1562. one of: "lsb2msb", "LSB2MSB", "msb2lsb", or "MSB2LSB".
  1563. EOF
  1564.         x="";;
  1565.         esac
  1566.     else
  1567.         x="$1"
  1568.     fi
  1569.     done
  1570.     param="$x"
  1571. }
  1572.  
  1573. #
  1574. # Prompt the user for a flow control scheme.
  1575. #
  1576. promptForFlowControlParameter()
  1577. {
  1578.     x=""
  1579.     while [ -z "$x" ]; do
  1580.     prompt "$2 [$1]?"; read x
  1581.     if [ "$x" ]; then
  1582.         # strip leading and trailing white space
  1583.         x=`echo "$x" | sed -e 's/^[     ]*//' -e 's/[     ]*$//'`
  1584.         case "$x" in
  1585.         xon*|XON*)    x="xonxoff";;
  1586.         rts*|RTS*)    x="rtscts";;
  1587.         *)
  1588. cat <<EOF
  1589.  
  1590. "$x" is not a valid bit order parameter setting; use
  1591. one of: "xonxoff", "XONXOFF", "rtscts", or "RTSCTS".
  1592. EOF
  1593.         x="";;
  1594.         esac
  1595.     else
  1596.         x="$1"
  1597.     fi
  1598.     done
  1599.     param="$x"
  1600. }
  1601.  
  1602. saveModemProtoParameters()
  1603. {
  1604.     protoModemAnswerAnyCmd="$ModemAnswerAnyCmd"
  1605.     protoModemAnswerBeginDataCmd="$ModemAnswerBeginDataCmd"
  1606.     protoModemAnswerBeginFaxCmd="$ModemAnswerBeginFaxCmd"
  1607.     protoModemAnswerBeginVoiceCmd="$ModemAnswerBeginVoiceCmd"
  1608.     protoModemAnswerCmd="$ModemAnswerCmd"
  1609.     protoModemAnswerDataCmd="$ModemAnswerDataCmd"
  1610.     protoModemAnswerFaxCmd="$ModemAnswerFaxCmd"
  1611.     protoModemAnswerResponseTimeout="$ModemAnswerResponseTimeout"
  1612.     protoModemAnswerVoiceCmd="$ModemAnswerVoiceCmd"
  1613.     protoModemBaudRateDelay="$ModemBaudRateDelay"
  1614.     protoModemCommaPauseTimeCmd="$ModemCommaPauseTimeCmd"
  1615.     protoModemDialCmd="$ModemDialCmd"
  1616.     protoModemDialResponseTimeout="$ModemDialResponseTimeout"
  1617.     protoModemEchoOffCmd="$ModemEchoOffCmd"
  1618.     protoModemFlowControl="$ModemFlowControl"
  1619.     protoModemFlowControlCmd="$ModemFlowControlCmd"
  1620.     protoModemFrameFillOrder="$ModemFrameFillOrder"
  1621.     protoModemHostFillOrder="$ModemHostFillOrder"
  1622.     protoModemInterPacketDelay="$ModemInterPacketDelay"
  1623.     protoModemMaxPacketSize="$ModemMaxPacketSize"
  1624.     protoModemMfrQueryCmd="$ModemMfrQueryCmd"
  1625.     protoModemModelQueryCmd="$ModemModelQueryCmd"
  1626.     protoModemNoAutoAnswerCmd="$ModemNoAutoAnswerCmd"
  1627.     protoModemOnHookCmd="$ModemOnHookCmd"
  1628.     protoModemPageDoneTimeout="$ModemPageDoneTimeout"
  1629.     protoModemPageStartTimeout="$ModemPageStartTimeout"
  1630.     protoModemRate="$ModemRate"
  1631.     protoModemRecvFillOrder="$ModemRecvFillOrder"
  1632.     protoModemResetCmds="$ModemResetCmds"
  1633.     protoModemResetDelay="$ModemResetDelay"
  1634.     protoModemResultCodesCmd="$ModemResultCodesCmd"
  1635.     protoModemRevQueryCmd="$ModemRevQueryCmd"
  1636.     protoModemSendFillOrder="$ModemSendFillOrder"
  1637.     protoModemSetVolumeCmd="$ModemSetVolumeCmd"
  1638.     protoModemSetupAACmd="$ModemSetupAACmd"
  1639.     protoModemSetupDCDCmd="$ModemSetupDCDCmd"
  1640.     protoModemSetupDTRCmd="$ModemSetupDTRCmd"
  1641.     protoModemSoftResetCmd="$ModemSoftResetCmd"
  1642.     protoModemVerboseResultsCmd="$ModemVerboseResultsCmd"
  1643.     protoModemWaitForConnect="$ModemWaitForConnect"
  1644.     protoModemWaitTimeCmd="$ModemWaitTimeCmd"
  1645.  
  1646.     protoFaxT1Timer="$FaxT1Timer"
  1647.     protoFaxT2Timer="$FaxT2Timer"
  1648.     protoFaxT4Timer="$FaxT4Timer"
  1649.     case "$ModemType" in
  1650.     Class1*)
  1651.     protoClass1Cmd="$Class1Cmd"
  1652.     protoClass1FrameOverhead="$Class1FrameOverhead"
  1653.     protoClass1RecvAbortOK="$Class1RecvAbortOK"
  1654.     protoClass1RecvIdentTimer="$Class1RecvIdentTimer"
  1655.     protoClass1SendPPMDelay="$Class1SendPPMDelay"
  1656.     protoClass1SendTCFDelay="$Class1SendTCFDelay"
  1657.     protoClass1TCFResponseDelay="$Class1TCFResponseDelay"
  1658.     protoClass1TrainingRecovery="$Class1TrainingRecovery"
  1659.     ;;
  1660.     Class2*)
  1661.     protoClass2AbortCmd="$Class2AbortCmd"
  1662.     protoClass2BORCmd="$Class2BORCmd"
  1663.     protoClass2BUGCmd="$Class2BUGCmd"
  1664.     protoClass2CIGCmd="$Class2CIGCmd"
  1665.     protoClass2CQCmd="$Class2CQCmd"
  1666.     protoClass2CRCmd="$Class2CRCmd"
  1667.     protoClass2Cmd="$Class2Cmd"
  1668.     protoClass2DCCCmd="$Class2DCCCmd"
  1669.     protoClass2DCCQueryCmd="$Class2DCCQueryCmd"
  1670.     protoClass2DISCmd="$Class2DISCmd"
  1671.     protoClass2LIDCmd="$Class2LIDCmd"
  1672.     protoClass2NRCmd="$Class2NRCmd"
  1673.     protoClass2PHCTOCmd="$Class2PHCTOCmd"
  1674.     protoClass2PIECmd="$Class2PIECmd"
  1675.     protoClass2RELCmd="$Class2RELCmd"
  1676.     protoClass2RecvDataTrigger="$Class2RecvDataTrigger"
  1677.     protoClass2SPLCmd="$Class2SPLCmd"
  1678.     protoClass2TBCCmd="$Class2TBCCmd"
  1679.     protoClass2XmitWaitForXON="$Class2XmitWaitForXON"
  1680.     ;;
  1681.     esac
  1682. }
  1683.  
  1684. #
  1685. # Get the default modem parameter values
  1686. # from the prototype configuration file.
  1687. #
  1688. getModemProtoParameters()
  1689. {
  1690.     getParameter ModemAnswerAnyCmd $1;        ModemAnswerAnyCmd="$param"
  1691.     getParameter ModemAnswerBeginDataCmd $1;    ModemAnswerBeginDataCmd="$param"
  1692.     getParameter ModemAnswerBeginFaxCmd $1;    ModemAnswerBeginFaxCmd="$param"
  1693.     getParameter ModemAnswerBeginVoiceCmd $1;    ModemAnswerBeginVoiceCmd="$param"
  1694.     getParameter ModemAnswerCmd $1;        ModemAnswerCmd="$param"
  1695.     getParameter ModemAnswerDataCmd $1;        ModemAnswerDataCmd="$param"
  1696.     getParameter ModemAnswerFaxCmd $1;        ModemAnswerFaxCmd="$param"
  1697.     getParameter ModemAnswerResponseTimeout $1;    ModemAnswerResponseTimeout="$param"
  1698.     getParameter ModemAnswerVoiceCmd $1;    ModemAnswerVoiceCmd="$param"
  1699.     getParameter ModemBaudRateDelay $1;        ModemBaudRateDelay="$param"
  1700.     getParameter ModemCommaPauseTimeCmd $1;    ModemCommaPauseTimeCmd="$param"
  1701.     getParameter ModemDialCmd $1;        ModemDialCmd="$param"
  1702.     getParameter ModemDialResponseTimeout $1;    ModemDialResponseTimeout="$param"
  1703.     getParameter ModemEchoOffCmd $1;        ModemEchoOffCmd="$param"
  1704.     getParameter ModemFlowControl $1;        ModemFlowControl="$param"
  1705.     getParameter ModemFlowControlCmd $1;    ModemFlowControlCmd="$param"
  1706.     getParameter ModemFrameFillOrder $1;    ModemFrameFillOrder="$param"
  1707.     getParameter ModemHostFillOrder $1;        ModemHostFillOrder="$param"
  1708.     getParameter ModemInterPacketDelay $1;    ModemInterPacketDelay="$param"
  1709.     getParameter ModemMaxPacketSize $1;        ModemMaxPacketSize="$param"
  1710.     getParameter ModemMfrQueryCmd $1;        ModemMfrQueryCmd="$param"
  1711.     getParameter ModemModelQueryCmd $1;        ModemModelQueryCmd="$param"
  1712.     getParameter ModemNoAutoAnswerCmd $1;    ModemNoAutoAnswerCmd="$param"
  1713.     getParameter ModemOnHookCmd $1;        ModemOnHookCmd="$param"
  1714.     getParameter ModemPageDoneTimeout $1;    ModemPageDoneTimeout="$param"
  1715.     getParameter ModemPageStartTimeout $1;    ModemPageStartTimeout="$param"
  1716.     getParameter ModemRate $1;            ModemRate="$param"
  1717.     getParameter ModemRecvFillOrder $1;        ModemRecvFillOrder="$param"
  1718.     getParameter ModemResetCmds $1;        ModemResetCmds="$param"
  1719.     getParameter ModemResetDelay $1;        ModemResetDelay="$param"
  1720.     getParameter ModemResultCodesCmd $1;    ModemResultCodesCmd="$param"
  1721.     getParameter ModemRevQueryCmd $1;        ModemRevQueryCmd="$param"
  1722.     getParameter ModemSendFillOrder $1;        ModemSendFillOrder="$param"
  1723.     getParameter ModemSetVolumeCmd $1;        ModemSetVolumeCmd="$param"
  1724.     getParameter ModemSetupAACmd $1;        ModemSetupAACmd="$param"
  1725.     getParameter ModemSetupDCDCmd $1;        ModemSetupDCDCmd="$param"
  1726.     getParameter ModemSetupDTRCmd $1;        ModemSetupDTRCmd="$param"
  1727.     getParameter ModemSoftResetCmd $1;        ModemSoftResetCmd="$param"
  1728.     getParameter ModemVerboseResultsCmd $1;    ModemVerboseResultsCmd="$param"
  1729.     getParameter ModemWaitForConnect $1;    ModemWaitForConnect="$param"
  1730.     getParameter ModemWaitTimeCmd $1;        ModemWaitTimeCmd="$param"
  1731.  
  1732.     getParameter FaxT1Timer $1;            FaxT1Timer="$param"
  1733.     getParameter FaxT2Timer $1;            FaxT2Timer="$param"
  1734.     getParameter FaxT4Timer $1;            FaxT4Timer="$param"
  1735.     case "$ModemType" in
  1736.     Class1*)
  1737.     getParameter Class1Cmd $1;        Class1Cmd="$param"
  1738.     getParameter Class1FrameOverhead $1;    Class1FrameOverhead="$param"
  1739.     getParameter Class1RecvAbortOK $1;    Class1RecvAbortOK="$param"
  1740.     getParameter Class1RecvIdentTimer $1;    Class1RecvIdentTimer="$param"
  1741.     getParameter Class1SendPPMDelay $1;    Class1SendPPMDelay="$param"
  1742.     getParameter Class1SendTCFDelay $1;    Class1SendTCFDelay="$param"
  1743.     getParameter Class1TCFResponseDelay $1;    Class1TCFResponseDelay="$param"
  1744.     getParameter Class1TrainingRecovery $1;    Class1TrainingRecovery="$param"
  1745.     ;;
  1746.     Class2*)
  1747.     getParameter Class2AbortCmd $1;        Class2AbortCmd="$param"
  1748.     getParameter Class2BORCmd $1;        Class2BORCmd="$param"
  1749.     getParameter Class2BUGCmd $1;        Class2BUGCmd="$param"
  1750.     getParameter Class2CIGCmd $1;        Class2CIGCmd="$param"
  1751.     getParameter Class2CQCmd $1;        Class2CQCmd="$param"
  1752.     getParameter Class2CRCmd $1;        Class2CRCmd="$param"
  1753.     getParameter Class2Cmd $1;        Class2Cmd="$param"
  1754.     getParameter Class2DCCCmd $1;        Class2DCCCmd="$param"
  1755.     getParameter Class2DCCQueryCmd $1;    Class2DCCQueryCmd="$param"
  1756.     getParameter Class2DISCmd $1;        Class2DISCmd="$param"
  1757.     getParameter Class2LIDCmd $1;        Class2LIDCmd="$param"
  1758.     getParameter Class2NRCmd $1;        Class2NRCmd="$param"
  1759.     getParameter Class2PHCTOCmd $1;        Class2PHCTOCmd="$param"
  1760.     getParameter Class2PIECmd $1;        Class2PIECmd="$param"
  1761.     getParameter Class2RELCmd $1;        Class2RELCmd="$param"
  1762.     getParameter Class2RecvDataTrigger $1;    Class2RecvDataTrigger="$param"
  1763.     getParameter Class2SPLCmd $1;        Class2SPLCmd="$param"
  1764.     getParameter Class2TBCCmd $1;        Class2TBCCmd="$param"
  1765.     getParameter Class2XmitWaitForXON $1;    Class2XmitWaitForXON="$param"
  1766.     ;;
  1767.     esac
  1768.  
  1769.     #
  1770.     # If a dialing prefix was being used, add it to the
  1771.     # dialing command string.  Perhaps this is too simplistic.
  1772.     #
  1773.     if [ "$DialingPrefix" ]; then
  1774.     ModemDialCmd="${DialingPrefix}${ModemDialCmd}"
  1775.     fi
  1776.     saveModemProtoParameters
  1777. }
  1778.  
  1779. addSedCmd()
  1780. {
  1781.     test "$1" != "$2" && {
  1782.     # escape backslashes to counteract shell parsing and sed magic chars
  1783.     x=`echo "$2" | sed 's/[&\\\\"]/\\\\&/g'`
  1784.     if [ `expr "$2" : "[^\"].*[ ]"` = 0 ]; then
  1785.         ModemCmds="$ModemCmds -e '/^$3:/s;\(:[     ]*\).*;\1$x;'"
  1786.     else
  1787.         ModemCmds="$ModemCmds -e '/^$3:/s;\(:[     ]*\).*;\1\"$x\";'"
  1788.     fi
  1789.     }
  1790. }
  1791.  
  1792. #
  1793. # Setup the sed commands for crafting the configuration file:
  1794. #
  1795. makeSedModemCommands()
  1796. {
  1797.     ModemCmds=""
  1798.  
  1799.     addSedCmd "$protoModemAnswerAnyCmd" \
  1800.     "$ModemAnswerAnyCmd"            ModemAnswerAnyCmd
  1801.     addSedCmd "$protoModemAnswerBeginDataCmd" \
  1802.     "$ModemAnswerBeginDataCmd"        ModemAnswerBeginDataCmd
  1803.     addSedCmd "$protoModemAnswerBeginFaxCmd" \
  1804.     "$ModemAnswerBeginFaxCmd"        ModemAnswerBeginFaxCmd
  1805.     addSedCmd "$protoModemAnswerBeginVoiceCmd" \
  1806.     "$ModemAnswerBeginVoiceCmd"        ModemAnswerBeginVoiceCmd
  1807.     addSedCmd "$protoModemAnswerCmd" \
  1808.     "$ModemAnswerCmd"            ModemAnswerCmd
  1809.     addSedCmd "$protoModemAnswerDataCmd" \
  1810.     "$ModemAnswerDataCmd"            ModemAnswerDataCmd
  1811.     addSedCmd "$protoModemAnswerFaxCmd" \
  1812.     "$ModemAnswerFaxCmd"            ModemAnswerFaxCmd
  1813.     addSedCmd "$protoModemAnswerResponseTimeout" \
  1814.     "$ModemAnswerResponseTimeout"        ModemAnswerResponseTimeout
  1815.     addSedCmd "$protoModemAnswerVoiceCmd" \
  1816.     "$ModemAnswerVoiceCmd"            ModemAnswerVoiceCmd
  1817.     addSedCmd "$protoModemBaudRateDelay" \
  1818.     "$ModemBaudRateDelay"            ModemBaudRateDelay
  1819.     addSedCmd "$protoModemCommaPauseTimeCmd" \
  1820.     "$ModemCommaPauseTimeCmd"        ModemCommaPauseTimeCmd
  1821.     addSedCmd "$protoModemDialCmd" \
  1822.     "$ModemDialCmd"                ModemDialCmd
  1823.     addSedCmd "$protoModemDialResponseTimeout" \
  1824.     "$ModemDialResponseTimeout"        ModemDialResponseTimeout
  1825.     addSedCmd "$protoModemEchoOffCmd" \
  1826.     "$ModemEchoOffCmd"            ModemEchoOffCmd
  1827.     addSedCmd "$protoModemFlowControl" \
  1828.     "$ModemFlowControl"            ModemFlowControl
  1829.     addSedCmd "$protoModemFlowControlCmd" \
  1830.     "$ModemFlowControlCmd"            ModemFlowControlCmd
  1831.     addSedCmd "$protoModemFrameFillOrder" \
  1832.     "$ModemFrameFillOrder"            ModemFrameFillOrder
  1833.     addSedCmd "$protoModemHostFillOrder" \
  1834.     "$ModemHostFillOrder"            ModemHostFillOrder
  1835.     addSedCmd "$protoModemInterPacketDelay" \
  1836.     "$ModemInterPacketDelay"        ModemInterPacketDelay
  1837.     addSedCmd "$protoModemMaxPacketSize" \
  1838.     "$ModemMaxPacketSize"            ModemMaxPacketSize
  1839.     addSedCmd "$protoModemMfrQueryCmd" \
  1840.     "$ModemMfrQueryCmd"            ModemMfrQueryCmd
  1841.     addSedCmd "$protoModemModelQueryCmd" \
  1842.     "$ModemModelQueryCmd"            ModemModelQueryCmd
  1843.     addSedCmd "$protoModemNoAutoAnswerCmd" \
  1844.     "$ModemNoAutoAnswerCmd"            ModemNoAutoAnswerCmd
  1845.     addSedCmd "$protoModemOnHookCmd" \
  1846.     "$ModemOnHookCmd"            ModemOnHookCmd
  1847.     addSedCmd "$protoModemPageDoneTimeout" \
  1848.     "$ModemPageDoneTimeout"            ModemPageDoneTimeout
  1849.     addSedCmd "$protoModemPageStartTimeout" \
  1850.     "$ModemPageStartTimeout"        ModemPageStartTimeout
  1851.     addSedCmd "$protoModemRate" \
  1852.     "$ModemRate"                ModemRate
  1853.     addSedCmd "$protoModemRecvFillOrder" \
  1854.     "$ModemRecvFillOrder"            ModemRecvFillOrder
  1855.     addSedCmd "$protoModemResetCmds" \
  1856.     "$ModemResetCmds"            ModemResetCmds
  1857.     addSedCmd "$protoModemResetDelay" \
  1858.     "$ModemResetDelay"            ModemResetDelay
  1859.     addSedCmd "$protoModemResultCodesCmd" \
  1860.     "$ModemResultCodesCmd"            ModemResultCodesCmd
  1861.     addSedCmd "$protoModemRevQueryCmd" \
  1862.     "$ModemRevQueryCmd"            ModemRevQueryCmd
  1863.     addSedCmd "$protoModemSendFillOrder" \
  1864.     "$ModemSendFillOrder"            ModemSendFillOrder
  1865.     addSedCmd "$protoModemSetVolumeCmd" \
  1866.     "$ModemSetVolumeCmd"            ModemSetVolumeCmd
  1867.     addSedCmd "$protoModemSetupAACmd" \
  1868.     "$ModemSetupAACmd"            ModemSetupAACmd
  1869.     addSedCmd "$protoModemSetupDCDCmd" \
  1870.     "$ModemSetupDCDCmd"            ModemSetupDCDCmd
  1871.     addSedCmd "$protoModemSetupDTRCmd" \
  1872.     "$ModemSetupDTRCmd"            ModemSetupDTRCmd
  1873.     addSedCmd "$protoModemSoftResetCmd" \
  1874.     "$ModemSoftResetCmd"            ModemSoftResetCmd
  1875.     addSedCmd "$protoModemVerboseResultsCmd" \
  1876.     "$ModemVerboseResultsCmd"        ModemVerboseResultsCmd
  1877.     addSedCmd "$protoModemWaitForConnect" \
  1878.     "$ModemWaitForConnect"            ModemWaitForConnect
  1879.     addSedCmd "$protoModemWaitTimeCmd" \
  1880.     "$ModemWaitTimeCmd"            ModemWaitTimeCmd
  1881.  
  1882.     addSedCmd "$protoFaxT1Timer" "$FaxT1Timer"    FaxT1Timer
  1883.     addSedCmd "$protoFaxT2Timer" "$FaxT2Timer"    FaxT2Timer
  1884.     addSedCmd "$protoFaxT4Timer" "$FaxT4Timer"    FaxT4Timer
  1885.     case "$ModemType" in
  1886.     Class1*)
  1887.     addSedCmd "$protoClass1Cmd" "$Class1Cmd" Class1Cmd
  1888.     addSedCmd "$protoClass1FrameOverhead" \
  1889.         "$Class1FrameOverhead"        Class1FrameOverhead
  1890.     addSedCmd "$protoClass1RecvAbortOK" \
  1891.         "$Class1RecvAbortOK"        Class1RecvAbortOK
  1892.     addSedCmd "$protoClass1RecvIdentTimer" \
  1893.         "$Class1RecvIdentTimer"        Class1RecvIdentTimer
  1894.     addSedCmd "$protoClass1SendPPMDelay" \
  1895.         "$Class1SendPPMDelay"        Class1SendPPMDelay
  1896.     addSedCmd "$protoClass1SendTCFDelay" \
  1897.         "$Class1SendTCFDelay"        Class1SendTCFDelay
  1898.     addSedCmd "$protoClass1TCFResponseDelay" \
  1899.         "$Class1TCFResponseDelay"        Class1TCFResponseDelay
  1900.     addSedCmd "$protoClass1TrainingRecovery" \
  1901.         "$Class1TrainingRecovery"        Class1TrainingRecovery
  1902.     ;;
  1903.     Class2*)
  1904.     addSedCmd "$protoClass2AbortCmd" \
  1905.         "$Class2AbortCmd"            Class2AbortCmd
  1906.     addSedCmd "$protoClass2BORCmd" \
  1907.         "$Class2BORCmd"            Class2BORCmd
  1908.     addSedCmd "$protoClass2BUGCmd" \
  1909.         "$Class2BUGCmd"            Class2BUGCmd
  1910.     addSedCmd "$protoClass2CIGCmd" \
  1911.         "$Class2CIGCmd"            Class2CIGCmd
  1912.     addSedCmd "$protoClass2CQCmd" \
  1913.         "$Class2CQCmd"            Class2CQCmd
  1914.     addSedCmd "$protoClass2CRCmd" \
  1915.         "$Class2CRCmd"            Class2CRCmd
  1916.     addSedCmd "$protoClass2Cmd" \
  1917.         "$Class2Cmd"            Class2Cmd
  1918.     addSedCmd "$protoClass2DCCCmd" \
  1919.         "$Class2DCCCmd"            Class2DCCCmd
  1920.     addSedCmd "$protoClass2DCCQueryCmd" \
  1921.         "$Class2DCCQueryCmd"        Class2DCCQueryCmd
  1922.     addSedCmd "$protoClass2DISCmd" \
  1923.         "$Class2DISCmd"            Class2DISCmd
  1924.     addSedCmd "$protoClass2LIDCmd" \
  1925.         "$Class2LIDCmd"            Class2LIDCmd
  1926.     addSedCmd "$protoClass2NRCmd" \
  1927.         "$Class2NRCmd"            Class2NRCmd
  1928.     addSedCmd "$protoClass2PHCTOCmd" \
  1929.         "$Class2PHCTOCmd"            Class2PHCTOCmd
  1930.     addSedCmd "$protoClass2PIECmd" \
  1931.         "$Class2PIECmd"            Class2PIECmd
  1932.     addSedCmd "$protoClass2RELCmd" \
  1933.         "$Class2RELCmd"            Class2RELCmd
  1934.     addSedCmd "$protoClass2RecvDataTrigger" \
  1935.         "$Class2RecvDataTrigger"        Class2RecvDataTrigger
  1936.     addSedCmd "$protoClass2SPLCmd" \
  1937.         "$Class2SPLCmd"            Class2SPLCmd
  1938.     addSedCmd "$protoClass2TBCCmd" \
  1939.         "$Class2TBCCmd"            Class2TBCCmd
  1940.     addSedCmd "$protoClass2XmitWaitForXON" \
  1941.         "$Class2XmitWaitForXON"        Class2XmitWaitForXON
  1942.     ;;
  1943.     esac
  1944. }
  1945.  
  1946. #
  1947. # Check if the configured flow control scheme is
  1948. # consistent with the tty device being used.
  1949. #
  1950. checkFlowControlAgainstTTY()
  1951. {
  1952.     case "$ModemFlowControl" in
  1953.     xonxoff|XONXOFF)
  1954.     if [ "$TTY" = "ttyf${PORT}" -a -c /dev/ttym${PORT} ]; then
  1955.         echo ""
  1956.         echo "Warning, the modem is setup to use software flow control,"
  1957.         echo "but the \"$TTY\" device is used with hardware flow control"
  1958.         prompt "Do you want to use \"ttym${PORT}\" instead [yes]?"
  1959.         read x
  1960.         if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
  1961.         TTY="ttym${PORT}"
  1962.         DEVID="`echo $TTY | tr '/' '_'`"
  1963.         CONFIG=$CPATH.$DEVID
  1964.         fi
  1965.     fi
  1966.     ;;
  1967.     rtscts|RTSCTS)
  1968.     if [ "$TTY" = "ttym${PORT}" -a -c /dev/ttyf${PORT} ]; then
  1969.         echo ""
  1970.         echo "Warning, the modem is setup to use hardware flow control,"
  1971.         echo "but the \"$TTY\" device does not honor the RTS/CTS signals."
  1972.         prompt "Do you want to use \"ttyf${PORT}\" instead [yes]?"
  1973.         read x
  1974.         if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
  1975.         TTY="ttyf${PORT}"
  1976.         DEVID="`echo $TTY | tr '/' '_'`"
  1977.         CONFIG=$CPATH.$DEVID
  1978.         fi
  1979.     fi
  1980.     ;;
  1981.     esac
  1982. }
  1983.  
  1984. printIfNotNull()
  1985. {
  1986.     test "$2" && {
  1987.     x=`echo "$2" | sed 's/\\\\/&&/g'`    # escape backslashes to shell
  1988.     echo "$1    $x"
  1989.     }
  1990. }
  1991.  
  1992. #
  1993. # Print the current modem-related parameters.
  1994. #
  1995. printModemConfig()
  1996. {
  1997.     echo ""
  1998.     echo "The modem configuration parameters are:"
  1999.     echo ""
  2000.     printIfNotNull "ModemAnswerCmd:    "    "$ModemAnswerCmd"
  2001.     printIfNotNull "ModemAnswerAnyCmd:"        "$ModemAnswerAnyCmd"
  2002.     printIfNotNull "ModemAnswerDataCmd:"    "$ModemAnswerDataCmd"
  2003.     printIfNotNull "ModemAnswerFaxCmd:"        "$ModemAnswerFaxCmd"
  2004.     printIfNotNull "ModemAnswerVoiceCmd:"    "$ModemAnswerVoiceCmd"
  2005.     printIfNotNull "ModemAnswerBeginDataCmd:"    "$ModemAnswerBeginDataCmd"
  2006.     printIfNotNull "ModemAnswerBeginFaxCmd:"    "$ModemAnswerBeginFaxCmd"
  2007.     printIfNotNull "ModemAnswerBeginVoiceCmd:"    "$ModemAnswerBeginVoiceCmd"
  2008.     printIfNotNull "ModemAnswerResponseTimeout:" "$ModemAnswerResponseTimeout"
  2009.     printIfNotNull "ModemBaudRateDelay:"    "$ModemBaudRateDelay"
  2010.     printIfNotNull "ModemCommaPauseTimeCmd:"    "$ModemCommaPauseTimeCmd"
  2011.     printIfNotNull "ModemDialCmd:    "    "$ModemDialCmd"
  2012.     printIfNotNull "ModemDialResponseTimeout:"    "$ModemDialResponseTimeout"
  2013.     printIfNotNull "ModemEchoOffCmd:    "    "$ModemEchoOffCmd"
  2014.     printIfNotNull "ModemFlowControl:"        "$ModemFlowControl"
  2015.     printIfNotNull "ModemFlowControlCmd:"    "$ModemFlowControlCmd"
  2016.     printIfNotNull "ModemFrameFillOrder:"    "$ModemFrameFillOrder"
  2017.     printIfNotNull "ModemHostFillOrder:"    "$ModemHostFillOrder"
  2018.     printIfNotNull "ModemInterPacketDelay:"    "$ModemInterPacketDelay"
  2019.     printIfNotNull "ModemMaxPacketSize:"    "$ModemMaxPacketSize"
  2020.     printIfNotNull "ModemMfrQueryCmd:"        "$ModemMfrQueryCmd"
  2021.     printIfNotNull "ModemModelQueryCmd:"    "$ModemModelQueryCmd"
  2022.     printIfNotNull "ModemNoAutoAnswerCmd:"    "$ModemNoAutoAnswerCmd"
  2023.     printIfNotNull "ModemOnHookCmd:    "    "$ModemOnHookCmd"
  2024.     printIfNotNull "ModemPageDoneTimeout:"    "$ModemPageDoneTimeout"
  2025.     printIfNotNull "ModemPageStartTimeout:"    "$ModemPageStartTimeout"
  2026.     printIfNotNull "ModemRate:    "        "$ModemRate"
  2027.     printIfNotNull "ModemRecvFillOrder:"    "$ModemRecvFillOrder"
  2028.     printIfNotNull "ModemResetCmds:    "    "$ModemResetCmds"
  2029.     printIfNotNull "ModemResetDelay:"        "$ModemResetDelay"
  2030.     printIfNotNull "ModemResultCodesCmd:"    "$ModemResultCodesCmd"
  2031.     printIfNotNull "ModemRevQueryCmd:"        "$ModemRevQueryCmd"
  2032.     printIfNotNull "ModemSendFillOrder:"    "$ModemSendFillOrder"
  2033.     printIfNotNull "ModemSetVolumeCmd:"        "$ModemSetVolumeCmd"
  2034.     printIfNotNull "ModemSetupAACmd:"        "$ModemSetupAACmd"
  2035.     printIfNotNull "ModemSetupDCDCmd:"        "$ModemSetupDCDCmd"
  2036.     printIfNotNull "ModemSetupDTRCmd:"        "$ModemSetupDTRCmd"
  2037.     printIfNotNull "ModemSoftResetCmd:"        "$ModemSoftResetCmd"
  2038.     printIfNotNull "ModemVerboseResultsCmd:"    "$ModemVerboseResultsCmd"
  2039.     printIfNotNull "ModemWaitForConnect:"    "$ModemWaitForConnect"
  2040.     printIfNotNull "ModemWaitTimeCmd:"        "$ModemWaitTimeCmd"
  2041.  
  2042.     printIfNotNull "FaxT1Timer:    "        "$FaxT1Timer"
  2043.     printIfNotNull "FaxT2Timer:    "        "$FaxT2Timer"
  2044.     printIfNotNull "FaxT4Timer:    "        "$FaxT4Timer"
  2045.     case "$ModemType" in
  2046.     Class1*)
  2047.     printIfNotNull "Class1Cmd:    "    "$Class1Cmd"
  2048.     printIfNotNull "Class1FrameOverhead:"    "$Class1FrameOverhead"
  2049.     printIfNotNull "Class1RecvAbortOK:"    "$Class1RecvAbortOK"
  2050.     printIfNotNull "Class1RecvIdentTimer:"    "$Class1RecvIdentTimer"
  2051.     printIfNotNull "Class1SendPPMDelay:"    "$Class1SendPPMDelay"
  2052.     printIfNotNull "Class1SendTCFDelay:"    "$Class1SendTCFDelay"
  2053.     printIfNotNull "Class1TCFResponseDelay:" "$Class1TCFResponseDelay"
  2054.     printIfNotNull "Class1TrainingRecovery:" "$Class1TrainingRecovery"
  2055.     ;;
  2056.     Class2*)
  2057.     printIfNotNull "Class2AbortCmd:"    "$Class2AbortCmd"
  2058.     printIfNotNull "Class2BORCmd:    "    "$Class2BORCmd"
  2059.     printIfNotNull "Class2BUGCmd:    "    "$Class2BUGCmd"
  2060.     printIfNotNull "Class2CIGCmd:    "    "$Class2CIGCmd"
  2061.     printIfNotNull "Class2CQCmd:    "    "$Class2CQCmd"
  2062.     printIfNotNull "Class2CRCmd:    "    "$Class2CRCmd"
  2063.     printIfNotNull "Class2Cmd:    "    "$Class2Cmd"
  2064.     printIfNotNull "Class2DCCCmd:    "    "$Class2DCCCmd"
  2065.     printIfNotNull "Class2DCCQueryCmd:"    "$Class2DCCQueryCmd"
  2066.     printIfNotNull "Class2DISCmd:    "    "$Class2DISCmd"
  2067.     printIfNotNull "Class2LIDCmd:    "    "$Class2LIDCmd"
  2068.     printIfNotNull "Class2NRCmd:    "    "$Class2NRCmd"
  2069.     printIfNotNull "Class2PHCTOCmd:    "    "$Class2PHCTOCmd"
  2070.     printIfNotNull "Class2PIECmd:    "    "$Class2PIECmd"
  2071.     printIfNotNull "Class2RELCmd:    "    "$Class2RELCmd"
  2072.     printIfNotNull "Class2RecvDataTrigger:"    "$Class2RecvDataTrigger"
  2073.     printIfNotNull "Class2SPLCmd:    "    "$Class2SPLCmd"
  2074.     printIfNotNull "Class2TBCCmd:    "    "$Class2TBCCmd"
  2075.     printIfNotNull "Class2XmitWaitForXON:"    "$Class2XmitWaitForXON"
  2076.     ;;
  2077.     esac
  2078.     echo ""
  2079. }
  2080.  
  2081. #
  2082. # Prompt the user to edit the current parameters.  Note that
  2083. # we can only edit parameters that are in the prototype config
  2084. # file; thus all the checks to see if the prototype value exists.
  2085. #
  2086. promptForModemParameters()
  2087. {
  2088.     test "$protoModemAnswerCmd" && {
  2089.     promptForATCmdParameter "$ModemAnswerCmd" \
  2090.         "Command for answering the phone"
  2091.     ModemAnswerCmd="$param";
  2092.     }
  2093.     test "$protoModemAnswerAnyCmd" && {
  2094.     promptForATCmdParameter "$ModemAnswerAnyCmd" \
  2095.         "Command for answering any type of call"
  2096.     ModemAnswerAnyCmd="$param";
  2097.     }
  2098.     test "$protoModemAnswerDataCmd" && {
  2099.     promptForATCmdParameter "$ModemAnswerDataCmd" \
  2100.         "Command for answering a data call"
  2101.     ModemAnswerDataCmd="$param";
  2102.     }
  2103.     test "$protoModemAnswerFaxCmd" && {
  2104.     promptForATCmdParameter "$ModemAnswerFaxCmd" \
  2105.         "Command for answering a fax call"
  2106.     ModemAnswerFaxCmd="$param";
  2107.     }
  2108.     test "$protoModemAnswerVoiceCmd" && {
  2109.     promptForATCmdParameter "$ModemAnswerVoiceCmd" \
  2110.         "Command for answering a voice call"
  2111.     ModemAnswerVoiceCmd="$param";
  2112.     }
  2113.     test "$protoModemAnswerBeginDataCmd" && {
  2114.     promptForATCmdParameter "$ModemAnswerBeginDataCmd" \
  2115.         "Command for start of a data call"
  2116.     ModemAnswerBeginDataCmd="$param";
  2117.     }
  2118.     test "$protoModemAnswerBeginFaxCmd" && {
  2119.     promptForATCmdParameter "$ModemAnswerBeginFaxCmd" \
  2120.         "Command for start of a fax call"
  2121.     ModemAnswerBeginFaxCmd="$param";
  2122.     }
  2123.     test "$protoModemAnswerBeginVoiceCmd" && {
  2124.     promptForATCmdParameter "$ModemAnswerBeginVoiceCmd" \
  2125.         "Command for start of a voice call"
  2126.     ModemAnswerBeginVoiceCmd="$param";
  2127.     }
  2128.     test "$protoModemAnswerResponseTimeout" && {
  2129.     promptForNumericParameter "$ModemAnswerResponseTimeout" \
  2130.         "Answer command response timeout (ms)"
  2131.     ModemAnswerResponseTimeout="$param";
  2132.     }
  2133.     test "$protoModemBaudRateDelay" && {
  2134.     promptForNumericParameter "$ModemBaudRateDelay" \
  2135.         "Delay after setting tty baud rate (ms)"
  2136.     ModemBaudRateDelay="$param";
  2137.     }
  2138.     test "$protoModemCommaPauseTimeCmd" && {
  2139.     promptForATCmdParameter "$ModemCommaPauseTimeCmd" \
  2140.         "Command for setting time to pause for \",\" in dialing string"
  2141.     ModemCommaPauseTimeCmd="$param";
  2142.     }
  2143.     test "$protoModemDialCmd" && {
  2144.     promptForATCmdParameter "$ModemDialCmd" \
  2145.         "Command for dialing (%s for number to dial)"
  2146.     ModemDialCmd="$param";
  2147.     }
  2148.     test "$protoModemDialResponseTimeout" && {
  2149.     promptForNumericParameter "$ModemDialResponseTimeout" \
  2150.         "Dialing command response timeout (ms)"
  2151.     ModemDialResponseTimeout="$param";
  2152.     }
  2153.     test "$protoModemEchoOffCmd" && {
  2154.     promptForATCmdParameter "$ModemEchoOffCmd" \
  2155.         "Command for disabling command echo"
  2156.     ModemEchoOffCmd="$param";
  2157.     }
  2158.     test "$protoModemFlowControl" && {
  2159.     promptForFlowControlParameter "$ModemFlowControl" \
  2160.         "DTE-DCE flow control scheme"
  2161.     ModemFlowControl="$param";
  2162.     }
  2163.     test "$protoModemFlowControlCmd" && {
  2164.     promptForATCmdParameter "$ModemFlowControlCmd" \
  2165.         "Command for setting DCE-DTE flow control"
  2166.     ModemFlowControlCmd="$param";
  2167.     }
  2168.     test "$protoModemFrameFillOrder" && {
  2169.     promptForBitOrderParameter "$ModemFrameFillOrder" \
  2170.         "Bit order for HDLC frames"
  2171.     ModemFrameFillOrder="$param";
  2172.     }
  2173.     test "$protoModemHostFillOrder" && {
  2174.     promptForBitOrderParameter "$ModemHostFillOrder" \
  2175.         "Bit oder of host"
  2176.     ModemHostFillOrder="$param";
  2177.     }
  2178.     test "$protoModemInterPacketDelay" && {
  2179.     promptForNumericParameter "$ModemInterPacketDelay" \
  2180.         "Delay between modem writes (ms)"
  2181.     ModemInterPacketDelay="$param";
  2182.     }
  2183.     test "$protoModemMaxPacketSize" && {
  2184.     promptForNumericParameter "$ModemMaxPacketSize" \
  2185.         "Maximum data to write to the modem at once (bytes)"
  2186.     ModemMaxPacketSize="$param";
  2187.     }
  2188.     test "$protoModemMfrQueryCmd" && {
  2189.     promptForATCmdParameter "$ModemMfrQueryCmd" \
  2190.         "Command for querying modem manufacture"
  2191.     ModemMfrQueryCmd="$param";
  2192.     }
  2193.     test "$protoModemModelQueryCmd" && {
  2194.     promptForATCmdParameter "$ModemModelQueryCmd" \
  2195.         "Command for querying modem model"
  2196.     ModemModelQueryCmd="$param";
  2197.     }
  2198.     test "$protoModemNoAutoAnswerCmd" && {
  2199.     promptForATCmdParameter "$ModemNoAutoAnswerCmd" \
  2200.         "Command for disabling auto-answer"
  2201.     ModemNoAutoAnswerCmd="$param";
  2202.     }
  2203.     test "$protoModemOnHookCmd" && {
  2204.     promptForATCmdParameter "$ModemOnHookCmd" \
  2205.         "Command for placing phone \"on hook\" (hangup)"
  2206.     ModemOnHookCmd="$param";
  2207.     }
  2208.     test "$protoModemPageDoneTimeout" && {
  2209.     promptForNumericParameter "$ModemPageDoneTimeout" \
  2210.         "Page send/receive timeout (ms)"
  2211.     ModemPageDoneTimeout="$param";
  2212.     }
  2213.     test "$protoModemPageStartTimeout" && {
  2214.     promptForNumericParameter "$ModemPageStartTimeout" \
  2215.         "Page send/receive timeout (ms)"
  2216.     ModemPageStartTimeout="$param";
  2217.     }
  2218.     test "$protoModemRate" && {
  2219.     promptForNumericParameter "$ModemRate" \
  2220.         "DTE-DCE communication baud rate"
  2221.     ModemRate="$param";
  2222.     }
  2223.     test "$protoModemRecvFillOrder" && {
  2224.     promptForBitOrderParameter "$ModemRecvFillOrder" \
  2225.         "Bit order that modem sends received facsimile data"
  2226.     ModemRecvFillOrder="$param";
  2227.     }
  2228.     test "$protoModemResetCmds" && {
  2229.     promptForATCmdParameter "$ModemResetCmds" \
  2230.         "Additional commands for resetting the modem"
  2231.     ModemResetCmds="$param";
  2232.     }
  2233.     test "$protoModemResetDelay" && {
  2234.     promptForNumericParameter "$ModemResetDelay" \
  2235.         "Delay after sending modem reset commands (ms)"
  2236.     ModemResetDelay="$param";
  2237.     }
  2238.     test "$protoModemResultCodesCmd" && {
  2239.     promptForATCmdParameter "$ModemResultCodesCmd" \
  2240.         "Command for enabling result codes"
  2241.     ModemResultCodesCmd="$param";
  2242.     }
  2243.     test "$protoModemRevQueryCmd" && {
  2244.     promptForATCmdParameter "$ModemRevQueryCmd" \
  2245.         "Command for querying modem firmware revision"
  2246.     ModemRevQueryCmd="$param";
  2247.     }
  2248.     test "$protoModemSendFillOrder" && {
  2249.     promptForBitOrderParameter "$ModemSendFillOrder" \
  2250.         "Bit order that modem expects for transmitted facsimile data"
  2251.     ModemSendFillOrder="$param";
  2252.     }
  2253.     test "$protoModemSetVolumeCmd" && {
  2254.     promptForATCmdParameter "$ModemSetVolumeCmd" \
  2255.         "Commands for setting modem speaker volume levels"
  2256.     ModemSetVolumeCmd="$param";
  2257.     }
  2258.     test "$protoModemSetupAACmd" && {
  2259.     promptForATCmdParameter "$ModemSetupAACmd" \
  2260.         "Command for setting up adaptive-answer"
  2261.     ModemSetupAACmd="$param";
  2262.     }
  2263.     test "$protoModemSetupDCDCmd" && {
  2264.     promptForATCmdParameter "$ModemSetupDCDCmd" \
  2265.         "Command for setting up DCD handling"
  2266.     ModemSetupDCDCmd="$param";
  2267.     }
  2268.     test "$protoModemSetupDTRCmd" && {
  2269.     promptForATCmdParameter "$ModemSetupDTRCmd" \
  2270.         "Command for setting up DTR handling"
  2271.     ModemSetupDTRCmd="$param";
  2272.     }
  2273.     test "$protoModemSoftResetCmd" && {
  2274.     promptForATCmdParameter "$ModemSoftResetCmd" \
  2275.         "Command for doing a soft reset"
  2276.     ModemSoftResetCmd="$param";
  2277.     }
  2278.     test "$protoModemVerboseResultsCmd" && {
  2279.     promptForATCmdParameter "$ModemVerboseResultsCmd" \
  2280.         "Command for enabling verbose result codes"
  2281.     ModemVerboseResultsCmd="$param";
  2282.     }
  2283.     test "$protoModemWaitForConnect" && {
  2284.     promptForBooleanParameter "$ModemWaitForConnect" \
  2285.         "Force server to wait for \"CONNECT\" response on answer"
  2286.     ModemWaitForConnect="$param";
  2287.     }
  2288.     test "$protoModemWaitTimeCmd" && {
  2289.     promptForATCmdParameter "$ModemWaitTimeCmd" \
  2290.         "Command for setting time to wait for carrier when dialing"
  2291.     ModemWaitTimeCmd="$param";
  2292.     }
  2293.  
  2294.     test "$protoFaxT1Timer" && {
  2295.     promptForATCmdParameter "$FaxT1Timer" "CCITT T.30 T1 timer (ms)"
  2296.     FaxT1Timer="$param";
  2297.     }
  2298.     test "$protoFaxT2Timer" && {
  2299.     promptForATCmdParameter "$FaxT2Timer" "CCITT T.30 T2 timer (ms)"
  2300.     FaxT2Timer="$param";
  2301.     }
  2302.     test "$protoFaxT4Timer" && {
  2303.     promptForATCmdParameter "$FaxT4Timer" "CCITT T.30 T4 timer (ms)"
  2304.     FaxT4Timer="$param";
  2305.     }
  2306.     case "$ModemType" in
  2307.     Class1*)
  2308.     test "$protoClass1Cmd" && {
  2309.         promptForATCmdParameter "$Class1Cmd" "Command to enter Class 1"
  2310.         Class1Cmd="$param";
  2311.     }
  2312.     test "$protoClass1FrameOverhead" && {
  2313.         promptForNumericParameter "$Class1FrameOverhead" \
  2314.         "Extra bytes in a received HDLC frame"
  2315.         Class1FrameOverhead="$param";
  2316.     }
  2317.     test "$protoClass1RecvAbortOK" && {
  2318.         promptForNumericParameter "$Class1RecvAbortOK" \
  2319.         "Maximum time to wait for \"OK\" after aborting a receive (ms)"
  2320.         Class1RecvAbortOK="$param";
  2321.     }
  2322.     test "$protoClass1RecvIdentTimer" && {
  2323.         promptForNumericParameter "$Class1RecvIdentTimer" 
  2324.         "Maximum wait for initial identification frame (ms)"
  2325.         Class1RecvIdentTimer="$param";
  2326.     }
  2327.     test "$protoClass1SendPPMDelay" && {
  2328.         promptForNumericParameter "$Class1SendPPMDelay" \
  2329.         "Delay before sending post-page message (ms)"
  2330.         Class1SendPPMDelay="$param";
  2331.     }
  2332.     test "$protoClass1SendTCFDelay" && {
  2333.         promptForNumericParameter "$Class1SendTCFDelay"  \
  2334.         "Delay between sending TCF and ack/nak (ms)"
  2335.         Class1SendTCFDelay="$param";
  2336.     }
  2337.     test "$protoClass1TCFResponseDelay" && {
  2338.         promptForNumericParameter "$Class1TCFResponseDelay" \
  2339.         "Delay before sending DCS and TCF (ms)"
  2340.         Class1TCFResponseDelay="$param";
  2341.     }
  2342.     test "$protoClass1TrainingRecovery" && {
  2343.         promptForNumericParameter "$Class1TrainingRecovery" \
  2344.         "Delay after failed training (ms)"
  2345.         Class1TrainingRecovery="$param";
  2346.     }
  2347.     ;;
  2348.     Class2*)
  2349.     test "$protoClass2Cmd" && {
  2350.         promptForATCmdParameter "$Class2Cmd" \
  2351.         "Command to enter Class $ModemType"
  2352.         Class2Cmd="$param";
  2353.     }
  2354.     test "$protoClass2AbortCmd" && {
  2355.         promptForATCmdParameter "$Class2AbortCmd" \
  2356.             "Command to abort an active session"
  2357.         Class2AbortCmd="$param";
  2358.     }
  2359.     test "$protoClass2BORCmd" && {
  2360.         promptForATCmdParameter "$Class2BORCmd" \
  2361.         "Command to setup data bit order"
  2362.         Class2BORCmd="$param";
  2363.     }
  2364.     test "$protoClass2BUGCmd" && {
  2365.         promptForATCmdParameter "$Class2BUGCmd" \
  2366.         "Command to enable HDLC frame tracing"
  2367.         Class2BUGCmd="$param";
  2368.     }
  2369.     test "$protoClass2CIGCmd" && {
  2370.         promptForATCmdParameter "$Class2CIGCmd" \
  2371.         "Command to set polling identifer"
  2372.         Class2CIGCmd="$param";
  2373.     }
  2374.     test "$protoClass2CQCmd" && {
  2375.         promptForATCmdParameter "$Class2CQCmd" \
  2376.         "Command to setup copy quality parameters"
  2377.         Class2CQCmd="$param";
  2378.     }
  2379.     test "$protoClass2CRCmd" && {
  2380.         promptForATCmdParameter "$Class2CRCmd" \
  2381.         "Command to enable receive capability"
  2382.         Class2CRCmd="$param";
  2383.     }
  2384.     test "$protoClass2DCCCmd" && {
  2385.         promptForATCmdParameter "$Class2DCCCmd" \
  2386.         "Command to set/constrain modem capabilities"
  2387.         Class2DCCCmd="$param";
  2388.     }
  2389.     test "$protoClass2DCCQueryCmd" && {
  2390.         promptForATCmdParameter "$Class2DCCQueryCmd" \
  2391.         "Command to query modem capabilities"
  2392.         Class2DCCQueryCmd="$param";
  2393.     }
  2394.     test "$protoClass2DISCmd" && {
  2395.         promptForATCmdParameter "$Class2DISCmd" \
  2396.         "Command to set session parameters"
  2397.         Class2DISCmd="$param";
  2398.     }
  2399.     test "$protoClass2LIDCmd" && {
  2400.         promptForATCmdParameter "$Class2LIDCmd" \
  2401.         "Command to set local identifier string"
  2402.         Class2LIDCmd="$param";
  2403.     }
  2404.     test "$protoClass2NRCmd" && {
  2405.         promptForATCmdParameter "$Class2NRCmd" \
  2406.         "Command to enable status reporting"
  2407.         Class2NRCmd="$param";
  2408.     }
  2409.     test "$protoClass2PHCTOCmd" && {
  2410.         promptForATCmdParameter "$Class2PHCTOCmd" \
  2411.         "Command to set Phase C timeout"
  2412.         Class2PHCTOCmd="$param";
  2413.     }
  2414.     test "$protoClass2PIECmd" && {
  2415.         promptForATCmdParameter "$Class2PIECmd" \
  2416.         "Command to disable procedure interrupt handling"
  2417.         Class2PIECmd="$param";
  2418.     }
  2419.     test "$protoClass2RELCmd" && {
  2420.         promptForATCmdParameter "$Class2RELCmd" \
  2421.         "Command to enable delivery of byte-aligned EOL codes"
  2422.         Class2RELCmd="$param";
  2423.     }
  2424.     test "$protoClass2RecvDataTrigger" && {
  2425.         promptForATCmdParameter "$Class2RecvDataTrigger" \
  2426.         "Character sent before receiving page data";
  2427.         Class2RecvDataTrigger="$param";
  2428.     }
  2429.     test "$protoClass2SPLCmd" && {
  2430.         promptForATCmdParameter "$Class2SPLCmd" \
  2431.         "Command to set polling request"
  2432.         Class2SPLCmd="$param";
  2433.     }
  2434.     test "$protoClass2TBCCmd" && {
  2435.         promptForATCmdParameter "$Class2TBCCmd" \
  2436.         "Command to enable DTE-DCE stream communication mode"
  2437.         Class2TBCCmd="$param";
  2438.     }
  2439.     test "$protoClass2XmitWaitForXON" && {
  2440.         promptForBooleanParameter "$Class2XmitWaitForXON" \
  2441.         "Wait for XON before sending page data"
  2442.         Class2XmitWaitForXON="$param";
  2443.     }
  2444.     ;;
  2445.     esac
  2446. }
  2447.  
  2448. #
  2449. # Construct the configuration file.
  2450. #
  2451. if [ $ProtoType = config.skel    \
  2452.   -o $ProtoType = config.class1    \
  2453.   -o $ProtoType = config.class2    \
  2454. ]; then
  2455.     # Go through each important parameter (sigh)
  2456. cat<<EOF
  2457.  
  2458. There is no prototype configuration file for your modem, so we will
  2459. have to fill in the appropriate parameters by hand.  You will need the
  2460. manual for how to program your modem to do this task.  In case you are
  2461. uncertain of the meaning of a configuration parameter you should
  2462. consult the config(4F) manual page for an explanation.
  2463.  
  2464. Note that modem commands are specified without a leading "AT".  The "AT"
  2465. will not be displayed in the prompts and if you include a leading "AT"
  2466. it will automatically be deleted.  Likewise quote marks (") will not be
  2467. displayed and will automatically be deleted.  You can use this facility
  2468. to supply null parameters as "".
  2469.  
  2470. Finally, beware that the set of parameters is long.  If you prefer to
  2471. use your favorite editor instead of this script you should fill things
  2472. in here as best you can and then edit the configuration file
  2473.  
  2474. "$CONFIG"
  2475.  
  2476. after completing this procedure.
  2477.  
  2478. EOF
  2479.     ok="no"
  2480. else
  2481.     ok="skip"
  2482. fi
  2483.  
  2484. getModemProtoParameters $proto
  2485. while [ "$ok" != "" -a "$ok" != "y" -a "$ok" != "yes" ]; do
  2486.     if [ "$ok" != "skip" ]; then
  2487.     promptForModemParameters
  2488.     fi
  2489.     printModemConfig
  2490.     if [ "$OS" = "IRIX" ]; then
  2491.     checkFlowControlAgainstTTY
  2492.     fi
  2493.     #
  2494.     # XXX not sure what kind of consistency checking that can
  2495.     # done w/o knowing more about the modem...
  2496.     #
  2497.     prompt "Are these ok [yes]?"; read ok
  2498. done
  2499. makeSedModemCommands
  2500.  
  2501. #
  2502. # Re-read the server-related prototype parameters from
  2503. # the prototype file that we know we're going to hand to
  2504. # sed and construct the sed substitute commands that
  2505. # transform things according to the typed-in values.
  2506. #
  2507. getServerProtoParameters $proto
  2508. #
  2509. # If getty use was previously enabled, try to sed any
  2510. # existing GettyArgs line in the prototype file.  Otherwise
  2511. # try to uncomment the GettyArgs line in the prototype
  2512. # file--though this is not likely to do the right thing (sigh).
  2513. #
  2514. if [ "$protoGettyArgs" ]; then
  2515.     addServerSedCmd "$protoGettyArgs" "$GettyArgs" GettyArgs
  2516. else
  2517.     ServerCmds="$ServerCmds -e '/GettyArgs:/s/^#//'"
  2518. fi
  2519. makeSedServerCommands
  2520.  
  2521. #
  2522. # All done with the prompting; edit up a config file!
  2523. #
  2524. if [ -f $CONFIG ]; then
  2525.     echo "Saving existing configuration file as \"$CONFIG.sav\"."
  2526.     mv $CONFIG $CONFIG.sav
  2527. fi
  2528. echo "Creating new configuration file \"$CONFIG\"."
  2529. eval sed "$ServerCmds" "$ModemCmds" '-e /CONFIG:/d' $proto >$CONFIG
  2530. chown $FAX $CONFIG; chgrp $faxGID $CONFIG; chmod 644 $CONFIG
  2531.  
  2532. #
  2533. # Create FIFO.<tty> special file.
  2534. #
  2535. FIFO=$SPOOL/FIFO.$DEVID
  2536. echo "Creating \"$FIFO\" in the spooling directory."
  2537. test -p $FIFO \
  2538.     || (mkfifo $FIFO) >/dev/null 2>&1 \
  2539.     || (mknod $FIFO p) >/dev/null 2>&1 \
  2540.     || { echo "Cannot create fifo \"$FIFO\""; exit 1; }
  2541. chown $FAX $FIFO; chgrp $faxGID $FIFO; chmod 600 $FIFO
  2542.  
  2543. echo "Done setting up the modem configuration."
  2544.  
  2545. #
  2546. # And, last but not least, startup a server for the modem.
  2547. #
  2548. echo ""
  2549. prompt "Startup a facsimile server for this modem [yes]?"; read x
  2550. if [ "$x" = "" -o "$x" = "yes" -o "$x" = "y" ]; then
  2551.     echo "$SERVERDIR/faxd -m /dev/$TTY&"
  2552.     $SERVERDIR/faxd -m /dev/$TTY&
  2553. fi
  2554. exec >/dev/null 2>&1
  2555.